Skip to content

Commit

Permalink
Use US timezone for DST tests. Closes #5617.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5418 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Nov 2, 2006
1 parent c7c3994 commit 6770c8d
Showing 1 changed file with 43 additions and 23 deletions.
66 changes: 43 additions & 23 deletions activesupport/test/core_ext/time_ext_test.rb
Expand Up @@ -10,21 +10,25 @@ def test_seconds_since_midnight
end end


def test_seconds_since_midnight_at_daylight_savings_time_start def test_seconds_since_midnight_at_daylight_savings_time_start
# dt: US: 2005 April 3rd 2:00am ST => April 3rd 3:00am DT with_us_timezone do
assert_equal 3600+59*60+59, Time.local(2005,4,3,1,59,59).seconds_since_midnight, 'just before DST start' # dt: US: 2005 April 3rd 2:00am ST => April 3rd 3:00am DT
assert_equal 3600+59*60+59+2,Time.local(2005,4,3,3, 0, 1).seconds_since_midnight, 'just after DST start' 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
end end


def test_seconds_since_midnight_at_daylight_savings_time_end def test_seconds_since_midnight_at_daylight_savings_time_end
# st: US: 2005 October 30th 2:00am DT => October 30th 1:00am ST with_us_timezone do
# avoid setting a time between 1:00 and 2:00 since that requires specifying whether DST is active # st: US: 2005 October 30th 2:00am DT => October 30th 1:00am ST
assert_equal 3599, Time.local(2005,10,30,0,59,59).seconds_since_midnight, 'just before DST end' # avoid setting a time between 1:00 and 2:00 since that requires specifying whether DST is active
assert_equal 3*3600+1, Time.local(2005,10,30,2, 0, 1).seconds_since_midnight, 'just after DST end' 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 # 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 ) # 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 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' 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
end end


def test_begining_of_week def test_begining_of_week
Expand Down Expand Up @@ -107,15 +111,19 @@ def test_ago
end end


def test_daylight_savings_time_crossings_backward_start def test_daylight_savings_time_crossings_backward_start
# dt: US: 2005 April 3rd 4:18am with_us_timezone do
assert_equal Time.local(2005,4,2,4,18,0), Time.local(2005,4,3,4,18,0).ago(86400), 'dt-1.day=>st' # dt: US: 2005 April 3rd 4:18am
assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(86400), 'st-1.day=>st' 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
end end


def test_daylight_savings_time_crossings_backward_end def test_daylight_savings_time_crossings_backward_end
# st: US: 2005 October 30th 4:03am with_us_timezone do
assert_equal Time.local(2005,10,29,4,3), Time.local(2005,10,30,4,3,0).ago(86400), 'st-1.day=>dt' # st: US: 2005 October 30th 4:03am
assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(86400), 'dt-1.day=>dt' 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
end end


def test_since def test_since
Expand All @@ -126,15 +134,19 @@ def test_since
end end


def test_daylight_savings_time_crossings_forward_start def test_daylight_savings_time_crossings_forward_start
# st: US: 2005 April 2nd 7:27pm with_us_timezone do
assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).since(86400), 'st+1.day=>dt' # st: US: 2005 April 2nd 7:27pm
assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400), 'dt+1.day=>dt' 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
end end


def test_daylight_savings_time_crossings_forward_end def test_daylight_savings_time_crossings_forward_end
# dt: US: 2005 October 30th 12:45am with_us_timezone do
assert_equal Time.local(2005,10,31,1,45,0), Time.local(2005,10,30,1,45,0).since(86400), 'dt+1.day=>st' # dt: US: 2005 October 30th 12:45am
assert_equal Time.local(2005,11, 1,1,45,0), Time.local(2005,10,31,1,45,0).since(86400), 'st+1.day=>st' 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
end end


def test_yesterday def test_yesterday
Expand Down Expand Up @@ -256,4 +268,12 @@ def test_last_month_on_31st
def test_xmlschema_is_available def test_xmlschema_is_available
assert_nothing_raised { Time.now.xmlschema } assert_nothing_raised { Time.now.xmlschema }
end end

protected
def with_us_timezone
old_tz, ENV['TZ'] = ENV['TZ'], 'US/Pacific'
yield
ensure
ENV['TZ'] = old_tz
end
end end

0 comments on commit 6770c8d

Please sign in to comment.