Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 5418

Show
Ignore:
Timestamp:
11/02/06 20:36:06 (2 years ago)
Author:
bitsweat
Message:

Use US timezone for DST tests. Closes #5617.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/test/core_ext/time_ext_test.rb

    r5388 r5418  
    1111 
    1212  def test_seconds_since_midnight_at_daylight_savings_time_start 
    13     # dt: US: 2005 April 3rd 2:00am ST => April 3rd 3:00am DT 
    14     assert_equal 3600+59*60+59,  Time.local(2005,4,3,1,59,59).seconds_since_midnight, 'just before DST start' 
    15     assert_equal 3600+59*60+59+2,Time.local(2005,4,3,3, 0, 1).seconds_since_midnight, 'just after DST start' 
     13    with_us_timezone do 
     14      # dt: US: 2005 April 3rd 2:00am ST => April 3rd 3:00am DT 
     15      assert_equal 3600+59*60+59,  Time.local(2005,4,3,1,59,59).seconds_since_midnight, 'just before DST start' 
     16      assert_equal 3600+59*60+59+2,Time.local(2005,4,3,3, 0, 1).seconds_since_midnight, 'just after DST start' 
     17    end 
    1618  end 
    1719 
    1820  def test_seconds_since_midnight_at_daylight_savings_time_end 
    19     # st: US: 2005 October 30th 2:00am DT => October 30th 1:00am ST 
    20     # avoid setting a time between 1:00 and 2:00 since that requires specifying whether DST is active 
    21     assert_equal 3599, Time.local(2005,10,30,0,59,59).seconds_since_midnight, 'just before DST end' 
    22     assert_equal 3*3600+1, Time.local(2005,10,30,2, 0, 1).seconds_since_midnight, 'just after DST end' 
    23  
    24     # now set a time between 1:00 and 2:00 by specifying whether DST is active 
    25     # uses: Time.local( sec, min, hour, day, month, year, wday, yday, isdst, tz ) 
    26     assert_equal 1*3600+30*60, Time.local(0,30,1,30,10,2005,0,0,true,'EST5EDT').seconds_since_midnight, 'before DST end' 
    27     assert_equal 2*3600+30*60, Time.local(0,30,1,30,10,2005,0,0,false,'EST5EDT').seconds_since_midnight, 'after DST end' 
     21    with_us_timezone do 
     22      # st: US: 2005 October 30th 2:00am DT => October 30th 1:00am ST 
     23      # avoid setting a time between 1:00 and 2:00 since that requires specifying whether DST is active 
     24      assert_equal 3599, Time.local(2005,10,30,0,59,59).seconds_since_midnight, 'just before DST end' 
     25      assert_equal 3*3600+1, Time.local(2005,10,30,2, 0, 1).seconds_since_midnight, 'just after DST end' 
     26 
     27      # now set a time between 1:00 and 2:00 by specifying whether DST is active 
     28      # uses: Time.local( sec, min, hour, day, month, year, wday, yday, isdst, tz ) 
     29      assert_equal 1*3600+30*60, Time.local(0,30,1,30,10,2005,0,0,true,'EST5EDT').seconds_since_midnight, 'before DST end' 
     30      assert_equal 2*3600+30*60, Time.local(0,30,1,30,10,2005,0,0,false,'EST5EDT').seconds_since_midnight, 'after DST end' 
     31    end 
    2832  end 
    2933 
     
    108112 
    109113  def test_daylight_savings_time_crossings_backward_start 
    110     # dt: US: 2005 April 3rd 4:18am 
    111     assert_equal Time.local(2005,4,2,4,18,0), Time.local(2005,4,3,4,18,0).ago(86400), 'dt-1.day=>st' 
    112     assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(86400), 'st-1.day=>st' 
     114    with_us_timezone do 
     115      # dt: US: 2005 April 3rd 4:18am 
     116      assert_equal Time.local(2005,4,2,4,18,0), Time.local(2005,4,3,4,18,0).ago(86400), 'dt-1.day=>st' 
     117      assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(86400), 'st-1.day=>st' 
     118    end 
    113119  end 
    114120 
    115121  def test_daylight_savings_time_crossings_backward_end 
    116     # st: US: 2005 October 30th 4:03am 
    117     assert_equal Time.local(2005,10,29,4,3), Time.local(2005,10,30,4,3,0).ago(86400), 'st-1.day=>dt' 
    118     assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(86400), 'dt-1.day=>dt' 
     122    with_us_timezone do 
     123      # st: US: 2005 October 30th 4:03am 
     124      assert_equal Time.local(2005,10,29,4,3), Time.local(2005,10,30,4,3,0).ago(86400), 'st-1.day=>dt' 
     125      assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(86400), 'dt-1.day=>dt' 
     126    end 
    119127  end 
    120128 
     
    127135 
    128136  def test_daylight_savings_time_crossings_forward_start 
    129     # st: US: 2005 April 2nd 7:27pm 
    130     assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).since(86400), 'st+1.day=>dt' 
    131     assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400), 'dt+1.day=>dt' 
     137    with_us_timezone do 
     138      # st: US: 2005 April 2nd 7:27pm 
     139      assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).since(86400), 'st+1.day=>dt' 
     140      assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400), 'dt+1.day=>dt' 
     141    end 
    132142  end 
    133143 
    134144  def test_daylight_savings_time_crossings_forward_end 
    135     # dt: US: 2005 October 30th 12:45am 
    136     assert_equal Time.local(2005,10,31,1,45,0), Time.local(2005,10,30,1,45,0).since(86400), 'dt+1.day=>st' 
    137     assert_equal Time.local(2005,11, 1,1,45,0), Time.local(2005,10,31,1,45,0).since(86400), 'st+1.day=>st' 
     145    with_us_timezone do 
     146      # dt: US: 2005 October 30th 12:45am 
     147      assert_equal Time.local(2005,10,31,1,45,0), Time.local(2005,10,30,1,45,0).since(86400), 'dt+1.day=>st' 
     148      assert_equal Time.local(2005,11, 1,1,45,0), Time.local(2005,10,31,1,45,0).since(86400), 'st+1.day=>st' 
     149    end 
    138150  end 
    139151 
     
    257269    assert_nothing_raised { Time.now.xmlschema } 
    258270  end 
     271 
     272  protected 
     273    def with_us_timezone 
     274      old_tz, ENV['TZ'] = ENV['TZ'], 'US/Pacific' 
     275      yield 
     276    ensure 
     277      ENV['TZ'] = old_tz 
     278    end 
    259279end