Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Monkey patch for broken Time.at in JRuby 1.7.3

View jruby_1.7.3_time_patch.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
if RUBY_PLATFORM =~ /java/i
# ruby-units monkey patches the Time class which in turn exposes a bug in
# JRuby (https://github.com/jruby/jruby/issues/565)
class Time
class << self
if defined?( Unit )
# ruby units got there first
alias agworld_ruby_time_at unit_time_at
alias agworld_unit_time_at at
else
alias agworld_ruby_time_at at
end
end
 
def self.at(arg, ms=nil)
if defined?( Unit )
# Unit existing implies ruby-units is loaded
if arg.kind_of?( Unit )
# call ruby-units' monkey patched Time.at, safe to pass through ms
# because ruby-units internally passes through to JRuby's Time.at with
# a float as the first arg and not a Time (which avoids the bug)
return agworld_unit_time_at( arg, ms )
end
end
# otherwise always call to Ruby's original Time.at
if ms.nil?
return agworld_ruby_time_at(arg)
else
return agworld_ruby_time_at(arg + (ms*0.000001))
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.