diff options
author | gbuesing <gbuesing@gmail.com> | 2008-04-12 19:35:47 -0500 |
---|---|---|
committer | gbuesing <gbuesing@gmail.com> | 2008-04-12 19:35:47 -0500 |
commit | 9620372a6dc7eeebdb04f1fdb7f150d29e60fc00 (patch) | |
tree | 602897010f85ae36f4849bd6ba0c0c9010986191 /activesupport/test/core_ext/time_ext_test.rb | |
parent | f285b6119b9ca7f598e31c0c8518dce3e1b13386 (diff) | |
download | rails-9620372a6dc7eeebdb04f1fdb7f150d29e60fc00.tar.gz rails-9620372a6dc7eeebdb04f1fdb7f150d29e60fc00.tar.bz2 rails-9620372a6dc7eeebdb04f1fdb7f150d29e60fc00.zip |
Time#since behaves correctly when passed a Duration. Closes #11527 [kemiller]
Diffstat (limited to 'activesupport/test/core_ext/time_ext_test.rb')
-rw-r--r-- | activesupport/test/core_ext/time_ext_test.rb | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index d1d92964c3..e53b7193ea 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -205,6 +205,31 @@ class TimeExtCalculationsTest < Test::Unit::TestCase end end + def test_daylight_savings_time_crossings_backward_start_1day + with_env_tz 'US/Eastern' do + # dt: US: 2005 April 3rd 4:18am + assert_equal Time.local(2005,4,2,4,18,0), Time.local(2005,4,3,4,18,0).ago(1.day), 'dt-1.day=>st' + assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(1.day), 'st-1.day=>st' + end + with_env_tz 'NZ' do + # dt: New Zealand: 2006 October 1st 4:18am + assert_equal Time.local(2006,9,30,4,18,0), Time.local(2006,10,1,4,18,0).ago(1.day), 'dt-1.day=>st' + assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(1.day), 'st-1.day=>st' + end + end + + def test_daylight_savings_time_crossings_backward_end_1day + with_env_tz 'US/Eastern' do + # st: US: 2005 October 30th 4:03am + assert_equal Time.local(2005,10,29,4,3), Time.local(2005,10,30,4,3,0).ago(1.day), 'st-1.day=>dt' + assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(1.day), 'dt-1.day=>dt' + end + with_env_tz 'NZ' do + # st: New Zealand: 2006 March 19th 4:03am + assert_equal Time.local(2006,3,18,4,3), Time.local(2006,3,19,4,3,0).ago(1.day), 'st-1.day=>dt' + assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(1.day), 'dt-1.day=>dt' + end + end def test_since assert_equal Time.local(2005,2,22,10,10,11), Time.local(2005,2,22,10,10,10).since(1) assert_equal Time.local(2005,2,22,11,10,10), Time.local(2005,2,22,10,10,10).since(3600) @@ -227,6 +252,19 @@ class TimeExtCalculationsTest < Test::Unit::TestCase end end + def test_daylight_savings_time_crossings_forward_start_1day + with_env_tz 'US/Eastern' do + # st: US: 2005 April 2nd 7:27pm + assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).since(1.day), 'st+1.day=>dt' + assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(1.day), 'dt+1.day=>dt' + end + with_env_tz 'NZ' do + # st: New Zealand: 2006 September 30th 7:27pm + assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,9,30,19,27,0).since(1.day), 'st+1.day=>dt' + assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(1.day), 'dt+1.day=>dt' + end + end + def test_daylight_savings_time_crossings_forward_start_tomorrow with_env_tz 'US/Eastern' do # st: US: 2005 April 2nd 7:27pm @@ -240,7 +278,7 @@ class TimeExtCalculationsTest < Test::Unit::TestCase end end - def test_daylight_savings_time_crossings_forward_start_yesterday + def test_daylight_savings_time_crossings_backward_start_yesterday with_env_tz 'US/Eastern' do # st: US: 2005 April 2nd 7:27pm assert_equal Time.local(2005,4,2,19,27,0), Time.local(2005,4,3,19,27,0).yesterday, 'dt-1.day=>st' @@ -266,6 +304,19 @@ class TimeExtCalculationsTest < Test::Unit::TestCase end end + def test_daylight_savings_time_crossings_forward_end_1day + with_env_tz 'US/Eastern' do + # dt: US: 2005 October 30th 12:45am + assert_equal Time.local(2005,10,31,0,45,0), Time.local(2005,10,30,0,45,0).since(1.day), 'dt+1.day=>st' + assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(1.day), 'st+1.day=>st' + end + with_env_tz 'NZ' do + # dt: New Zealand: 2006 March 19th 1:45am + assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,19,1,45,0).since(1.day), 'dt+1.day=>st' + assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(1.day), 'st+1.day=>st' + end + end + def test_daylight_savings_time_crossings_forward_end_tomorrow with_env_tz 'US/Eastern' do # dt: US: 2005 October 30th 12:45am @@ -279,7 +330,7 @@ class TimeExtCalculationsTest < Test::Unit::TestCase end end - def test_daylight_savings_time_crossings_forward_end_yesterday + def test_daylight_savings_time_crossings_backward_end_yesterday with_env_tz 'US/Eastern' do # dt: US: 2005 October 30th 12:45am assert_equal Time.local(2005,10,30,0,45,0), Time.local(2005,10,31,0,45,0).yesterday, 'st-1.day=>dt' |