diff options
author | Riley Lynch <oss+rails@teleological.net> | 2013-05-15 08:59:52 -0400 |
---|---|---|
committer | Riley Lynch <oss+rails@teleological.net> | 2013-05-15 10:12:04 -0400 |
commit | 0c6ddbe7b0056cb5c17d6b483c0e5a7cbd596b97 (patch) | |
tree | 94d7032ecac8c6fadd195ec6278de788b80bfefd /activesupport/test/core_ext/time_ext_test.rb | |
parent | e2f3e502291d3d9fa8d5f0f65644c961ec020c69 (diff) | |
download | rails-0c6ddbe7b0056cb5c17d6b483c0e5a7cbd596b97.tar.gz rails-0c6ddbe7b0056cb5c17d6b483c0e5a7cbd596b97.tar.bz2 rails-0c6ddbe7b0056cb5c17d6b483c0e5a7cbd596b97.zip |
Maintain proleptic gregorian in Time#advance
Time#advance uses Time#to_date and Date#advance to calculate a new date.
The Date object returned by Time#to_date is constructed with the assumption
that the Time object represents a proleptic gregorian date, but it is
configured to observe the default julian calendar reform date (2299161j)
for purposes of calculating month, date and year:
Time.new(1582, 10, 4).to_date.to_s # => "1582-09-24"
Time.new(1582, 10, 4).to_date.gregorian.to_s # => "1582-10-04"
This patch ensures that when the intermediate Date object is advanced
to yield a new Date object, that the Time object for return is contructed
with a proleptic gregorian month, date and year.
Diffstat (limited to 'activesupport/test/core_ext/time_ext_test.rb')
-rw-r--r-- | activesupport/test/core_ext/time_ext_test.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 4e53aff00b..7ff4ea9d65 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -464,6 +464,13 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase assert_equal t, t.advance(:months => 0) end + def test_advance_gregorian_proleptic + assert_equal Time.local(1582,10,14,15,15,10), Time.local(1582,10,15,15,15,10).advance(:days => -1) + assert_equal Time.local(1582,10,15,15,15,10), Time.local(1582,10,14,15,15,10).advance(:days => 1) + assert_equal Time.local(1582,10,5,15,15,10), Time.local(1582,10,4,15,15,10).advance(:days => 1) + assert_equal Time.local(1582,10,4,15,15,10), Time.local(1582,10,5,15,15,10).advance(:days => -1) + end + def test_last_week with_env_tz 'US/Eastern' do assert_equal Time.local(2005,2,21), Time.local(2005,3,1,15,15,10).last_week |