class TZInfo::Timestamp
A time represented as an `Integer` number of seconds since 1970-01-01 00:00:00 UTC (ignoring leap seconds), the fraction through the second (sub_second as a `Rational`) and an optional UTC offset. Like Ruby's `Time` class, {Timestamp} can distinguish between a local time with a zero offset and a time specified explicitly as UTC.
Protected Instance Methods
new_datetime(klass = DateTime)
click to toggle source
# File lib/logstash/inputs/tzinfo_jruby_patch.rb, line 35 def new_datetime(klass = DateTime) val = JD_EPOCH + ((@value.to_r + @sub_second) / 86400) datetime = klass.jd(jruby_scale_down_rational(val)) @utc_offset && @utc_offset != 0 ? datetime.new_offset(Rational(@utc_offset, 86400)) : datetime end
Private Instance Methods
jruby_scale_down_rational(rat)
click to toggle source
while this JRuby bug exists in 9.2.X.X github.com/jruby/jruby/issues/5791 we must scale down the numerator and denominator to fit Java Long values.
# File lib/logstash/inputs/tzinfo_jruby_patch.rb, line 46 def jruby_scale_down_rational(rat) return rat if rat.numerator <= java.lang.Long::MAX_VALUE [10, 100, 1000].each do |scale_by| new_numerator = rat.numerator / scale_by if new_numerator <= java.lang.Long::MAX_VALUE return Rational(new_numerator, rat.denominator / scale_by) end end end