1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

TimeWithZone #+ and #- : ensure overflow to DateTime with Numeric arg

This commit is contained in:
gbuesing 2008-05-18 11:15:29 -05:00
parent e30a263bf1
commit cde9c09a52
3 changed files with 11 additions and 2 deletions

View file

@ -1,3 +1,5 @@
* TimeWithZone #+ and #- : ensure overflow to DateTime with Numeric arg [Geoff Buesing]
* Time#to_json: don't convert to utc before encoding. References #175 [Geoff Buesing]
*2.1.0 RC1 (May 11th, 2008)*

View file

@ -135,7 +135,7 @@ module ActiveSupport
# If wrapped #time is a DateTime, use DateTime#since instead of #+
# Otherwise, just pass on to #method_missing
def +(other)
result = utc.acts_like?(:date) ? utc.since(other) : utc + other
result = utc.acts_like?(:date) ? utc.since(other) : utc + other rescue utc.since(other)
result.in_time_zone(time_zone)
end
@ -146,7 +146,7 @@ module ActiveSupport
if other.acts_like?(:time)
utc - other
else
result = utc.acts_like?(:date) ? utc.ago(other) : utc - other
result = utc.acts_like?(:date) ? utc.ago(other) : utc - other rescue utc.ago(other)
result.in_time_zone(time_zone)
end
end

View file

@ -170,6 +170,13 @@ class TimeWithZoneTest < Test::Unit::TestCase
assert_equal DateTime.civil(1999, 12, 31, 19, 0 ,5), (twz + 5).time
end
end
def test_plus_when_crossing_time_class_limit
silence_warnings do # silence warnings raised by tzinfo gem
twz = ActiveSupport::TimeWithZone.new(Time.utc(2038, 1, 19), @time_zone)
assert_equal [0, 0, 19, 19, 1, 2038], (twz + 86_400).to_a[0,6]
end
end
def test_plus_with_duration
silence_warnings do # silence warnings raised by tzinfo gem