aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/time_ext_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-11-02 01:52:11 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-11-02 01:52:11 +0000
commit5ba85d84fb3d18d28a3a6bc801286aad09f42014 (patch)
treea269a19a436372f59f98cf9e4d34f38b56a56127 /activesupport/test/core_ext/time_ext_test.rb
parent5cc682da0786478e95a7fde04fafa69808341efb (diff)
downloadrails-5ba85d84fb3d18d28a3a6bc801286aad09f42014.tar.gz
rails-5ba85d84fb3d18d28a3a6bc801286aad09f42014.tar.bz2
rails-5ba85d84fb3d18d28a3a6bc801286aad09f42014.zip
next_week respects DST changes. Closes #5617, closes #2353, closes #2509, references #4551.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5388 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/core_ext/time_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index dc58401c3e..2c32ed3d5a 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -9,6 +9,24 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
assert_equal 60.00001,Time.local(2005,1,1,0,1,0,10).seconds_since_midnight
end
+ def test_seconds_since_midnight_at_daylight_savings_time_start
+ # dt: US: 2005 April 3rd 2:00am ST => April 3rd 3:00am DT
+ assert_equal 3600+59*60+59, Time.local(2005,4,3,1,59,59).seconds_since_midnight, 'just before DST start'
+ assert_equal 3600+59*60+59+2,Time.local(2005,4,3,3, 0, 1).seconds_since_midnight, 'just after DST start'
+ end
+
+ def test_seconds_since_midnight_at_daylight_savings_time_end
+ # st: US: 2005 October 30th 2:00am DT => October 30th 1:00am ST
+ # avoid setting a time between 1:00 and 2:00 since that requires specifying whether DST is active
+ assert_equal 3599, Time.local(2005,10,30,0,59,59).seconds_since_midnight, 'just before DST end'
+ assert_equal 3*3600+1, Time.local(2005,10,30,2, 0, 1).seconds_since_midnight, 'just after DST end'
+
+ # now set a time between 1:00 and 2:00 by specifying whether DST is active
+ # uses: Time.local( sec, min, hour, day, month, year, wday, yday, isdst, tz )
+ assert_equal 1*3600+30*60, Time.local(0,30,1,30,10,2005,0,0,true,'EST5EDT').seconds_since_midnight, 'before DST end'
+ assert_equal 2*3600+30*60, Time.local(0,30,1,30,10,2005,0,0,false,'EST5EDT').seconds_since_midnight, 'after DST end'
+ end
+
def test_begining_of_week
assert_equal Time.local(2005,1,31), Time.local(2005,2,4,10,10,10).beginning_of_week
assert_equal Time.local(2005,11,28), Time.local(2005,11,28,0,0,0).beginning_of_week #monday
@@ -88,6 +106,18 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
assert_equal Time.local(2005,2,20,9,9,45), Time.local(2005,2,22,10,10,10).ago(86400*2 + 3600 + 25)
end
+ def test_daylight_savings_time_crossings_backward_start
+ # 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(86400), 'dt-1.day=>st'
+ assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(86400), 'st-1.day=>st'
+ end
+
+ def test_daylight_savings_time_crossings_backward_end
+ # 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(86400), 'st-1.day=>dt'
+ assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(86400), 'dt-1.day=>dt'
+ 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)
@@ -95,6 +125,18 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
assert_equal Time.local(2005,2,24,11,10,35), Time.local(2005,2,22,10,10,10).since(86400*2 + 3600 + 25)
end
+ def test_daylight_savings_time_crossings_forward_start
+ # 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(86400), 'st+1.day=>dt'
+ assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400), 'dt+1.day=>dt'
+ end
+
+ def test_daylight_savings_time_crossings_forward_end
+ # dt: US: 2005 October 30th 12:45am
+ assert_equal Time.local(2005,10,31,1,45,0), Time.local(2005,10,30,1,45,0).since(86400), 'dt+1.day=>st'
+ assert_equal Time.local(2005,11, 1,1,45,0), Time.local(2005,10,31,1,45,0).since(86400), 'st+1.day=>st'
+ end
+
def test_yesterday
assert_equal Time.local(2005,2,21,10,10,10), Time.local(2005,2,22,10,10,10).yesterday
assert_equal Time.local(2005,2,28,10,10,10), Time.local(2005,3,2,10,10,10).yesterday.yesterday
@@ -150,6 +192,14 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
assert_equal Time.local(2006,11,1), Time.local(2006,10,23,0,0,0).next_week(:wednesday)
end
+ def test_next_week_near_daylight_start
+ assert_equal Time.local(2006,4,3), Time.local(2006,4,2,23,1,0).next_week, 'just crossed standard => daylight'
+ end
+
+ def test_next_week_near_daylight_end
+ assert_equal Time.local(2006,10,30), Time.local(2006,10,29,23,1,0).next_week, 'just crossed daylight => standard'
+ end
+
def test_to_s
time = Time.local(2005, 2, 21, 17, 44, 30)
assert_equal "2005-02-21 17:44:30", time.to_s(:db)