Permalink
Browse files

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

  • Loading branch information...
1 parent e30a263 commit cde9c09a524a21214ea9cd0f9ee4489e4d185af2 @gbuesing gbuesing committed May 18, 2008
View
@@ -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)*
@@ -135,7 +135,7 @@ def eql?(other)
# 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 @@ def -(other)
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
@@ -170,6 +170,13 @@ def test_plus_with_integer_when_self_wraps_datetime
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

0 comments on commit cde9c09

Please sign in to comment.