mirror of
https://github.com/github/rails.git
synced 2026-01-30 16:58:15 -05:00
TimeWithZone #+ and #- : ensure overflow to DateTime with Numeric arg
This commit is contained in:
@@ -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 @@ 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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user