aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb4
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb7
3 files changed, 11 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index dabb6a0c6f..7f2c3e971a 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -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)*
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 48606dbcff..15145a2575 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -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
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 70c393dd46..c373bca88d 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -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