lib/tzinfo/time_with_offset.rb in tzinfo-2.0.2 vs lib/tzinfo/time_with_offset.rb in tzinfo-2.0.3
- old
+ new
@@ -44,10 +44,26 @@
to = timezone_offset
to ? to.dst? : super
end
alias isdst dst?
+ # An overridden version of `Time#getlocal` that clears the associated
+ # {TimezoneOffset} if the base implementation of `getlocal` returns a
+ # {TimeWithOffset}.
+ #
+ # @return [Time] a representation of the {TimeWithOffset} using either the
+ # local time zone or the given offset.
+ def getlocal(*args)
+ # JRuby < 9.3 returns a Time in all cases.
+ # JRuby >= 9.3 returns a Time when called with no arguments and a
+ # TimeWithOffset with a timezone_offset assigned when called with an
+ # offset argument.
+ result = super
+ result.clear_timezone_offset if result.kind_of?(TimeWithOffset)
+ result
+ end
+
# An overridden version of `Time#gmtime` that clears the associated
# {TimezoneOffset}.
#
# @return [TimeWithOffset] `self`.
def gmtime
@@ -121,8 +137,18 @@
offset = dt.offset
result = DateTimeWithOffset.jd(dt.jd + dt.day_fraction - offset)
result = result.new_offset(offset) unless offset == 0
result.set_timezone_offset(o)
end
+ end
+
+ protected
+
+ # Clears the associated {TimezoneOffset}.
+ #
+ # @return [TimeWithOffset] `self`.
+ def clear_timezone_offset
+ @timezone_offset = nil
+ self
end
end
end