diff options
author | Xavier Noria <fxn@hashref.com> | 2010-05-09 01:20:23 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-05-09 01:20:23 +0200 |
commit | 636ffa1f089a51c98fce616191846eaba93d7b87 (patch) | |
tree | a8c0178a4eccfb55253f957e5bc2015381fb4975 /activesupport/test | |
parent | 605c6455ac722ed9679e17458a47cc649cdedab0 (diff) | |
download | rails-636ffa1f089a51c98fce616191846eaba93d7b87.tar.gz rails-636ffa1f089a51c98fce616191846eaba93d7b87.tar.bz2 rails-636ffa1f089a51c98fce616191846eaba93d7b87.zip |
Backports Date#>> from 1.9 so that calculations do the right thing around the calendar reform
Our next_month gives November for some late dates in September of 1582.
Related methods, last_*, and in general advance have the same issues.
This commit fixes those, see the test suite for expected behavior, which
we still run in 1.9 to ensure it matches as we do with other methods
defined in Date in 1.9.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/date_ext_test.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index d5f3eed8c1..e70fc729ce 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -145,6 +145,10 @@ class DateExtCalculationsTest < Test::Unit::TestCase assert_equal Date.new(1999,2,28), Date.new(2000,2,29).last_year end + def test_last_year_in_calendar_reform + assert_equal Date.new(1582,10,4), Date.new(1583,10,14).last_year + end + def test_next_year assert_equal Date.new(2006,6,5), Date.new(2005,6,5).next_year end @@ -153,16 +157,28 @@ class DateExtCalculationsTest < Test::Unit::TestCase assert_equal Date.new(2001,2,28), Date.new(2000,2,29).next_year end + def test_next_year_in_calendar_reform + assert_equal Date.new(1582,10,4), Date.new(1581,10,10).next_year + end + def test_yesterday assert_equal Date.new(2005,2,21), Date.new(2005,2,22).yesterday assert_equal Date.new(2005,2,28), Date.new(2005,3,2).yesterday.yesterday end + def test_yesterday_in_calendar_reform + assert_equal Date.new(1582,10,4), Date.new(1582,10,15).yesterday + end + def test_tomorrow assert_equal Date.new(2005,2,23), Date.new(2005,2,22).tomorrow assert_equal Date.new(2005,3,2), Date.new(2005,2,28).tomorrow.tomorrow end + def test_tomorrow_in_calendar_reform + assert_equal Date.new(1582,10,15), Date.new(1582,10,4).tomorrow + end + def test_advance assert_equal Date.new(2006,2,28), Date.new(2005,2,28).advance(:years => 1) assert_equal Date.new(2005,6,28), Date.new(2005,2,28).advance(:months => 4) @@ -174,6 +190,17 @@ class DateExtCalculationsTest < Test::Unit::TestCase assert_equal Date.new(2005,2,28), Date.new(2004,2,29).advance(:years => 1) #leap day plus one year end + def test_advance_calendar_reform + assert_equal Date.new(1582,10,15), Date.new(1582,10,4).advance(:days => 1) + assert_equal Date.new(1582,10,4), Date.new(1582,10,15).advance(:days => -1) + 5.upto(14) do |day| + assert_equal Date.new(1582,10,4), Date.new(1582,9,day).advance(:months => 1) + assert_equal Date.new(1582,10,4), Date.new(1582,11,day).advance(:months => -1) + assert_equal Date.new(1582,10,4), Date.new(1581,10,day).advance(:years => 1) + assert_equal Date.new(1582,10,4), Date.new(1583,10,day).advance(:years => -1) + end + end + def test_next_week assert_equal Date.new(2005,2,28), Date.new(2005,2,22).next_week assert_equal Date.new(2005,3,4), Date.new(2005,2,22).next_week(:friday) |