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

Changeset 9221

Show
Ignore:
Timestamp:
04/04/08 03:29:30 (8 months ago)
Author:
gbuesing
Message:

Time #yesterday and #tomorrow behave correctly crossing DST boundary. Closes #7399 [sblackstone]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r9213 r9221  
    11*SVN* 
     2 
     3* Time #yesterday and #tomorrow behave correctly crossing DST boundary. Closes #7399 [sblackstone] 
    24 
    35* TimeWithZone: Adding tests for dst and leap day edge cases when advancing time [Geoff Buesing] 
  • trunk/activesupport/lib/active_support/core_ext/time/calculations.rb

    r8934 r9221  
    222222        # Convenience method which returns a new Time representing the time 1 day ago 
    223223        def yesterday 
    224           self.ago(1.day
     224          advance(:days => -1
    225225        end 
    226226 
    227227        # Convenience method which returns a new Time representing the time 1 day since the instance time 
    228228        def tomorrow 
    229           self.since(1.day
     229          advance(:days => 1
    230230        end 
    231231 
  • trunk/activesupport/test/core_ext/time_ext_test.rb

    r9002 r9221  
    228228  end 
    229229 
     230  def test_daylight_savings_time_crossings_forward_start_tomorrow 
     231    with_env_tz 'US/Eastern' do 
     232      # st: US: 2005 April 2nd 7:27pm 
     233      assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).tomorrow, 'st+1.day=>dt' 
     234      assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).tomorrow, 'dt+1.day=>dt' 
     235    end 
     236    with_env_tz 'NZ' do 
     237      # st: New Zealand: 2006 September 30th 7:27pm 
     238      assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,9,30,19,27,0).tomorrow, 'st+1.day=>dt' 
     239      assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).tomorrow, 'dt+1.day=>dt' 
     240    end 
     241  end 
     242 
     243  def test_daylight_savings_time_crossings_forward_start_yesterday 
     244    with_env_tz 'US/Eastern' do 
     245      # st: US: 2005 April 2nd 7:27pm 
     246      assert_equal Time.local(2005,4,2,19,27,0), Time.local(2005,4,3,19,27,0).yesterday, 'dt-1.day=>st' 
     247      assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,4,19,27,0).yesterday, 'dt-1.day=>dt' 
     248    end 
     249    with_env_tz 'NZ' do 
     250      # st: New Zealand: 2006 September 30th 7:27pm 
     251      assert_equal Time.local(2006,9,30,19,27,0), Time.local(2006,10,1,19,27,0).yesterday, 'dt-1.day=>st' 
     252      assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,10,2,19,27,0).yesterday, 'dt-1.day=>dt' 
     253    end 
     254  end 
     255 
    230256  def test_daylight_savings_time_crossings_forward_end 
    231257    with_env_tz 'US/Eastern' do 
     
    238264      assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,19,1,45,0).since(86400), 'dt+1.day=>st' 
    239265      assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(86400), 'st+1.day=>st' 
     266    end 
     267  end 
     268 
     269  def test_daylight_savings_time_crossings_forward_end_tomorrow 
     270    with_env_tz 'US/Eastern' do 
     271      # dt: US: 2005 October 30th 12:45am 
     272      assert_equal Time.local(2005,10,31,0,45,0), Time.local(2005,10,30,0,45,0).tomorrow, 'dt+1.day=>st' 
     273      assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).tomorrow, 'st+1.day=>st' 
     274    end 
     275    with_env_tz 'NZ' do 
     276      # dt: New Zealand: 2006 March 19th 1:45am 
     277      assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,19,1,45,0).tomorrow, 'dt+1.day=>st' 
     278      assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).tomorrow, 'st+1.day=>st' 
     279    end 
     280  end 
     281 
     282  def test_daylight_savings_time_crossings_forward_end_yesterday 
     283    with_env_tz 'US/Eastern' do 
     284      # dt: US: 2005 October 30th 12:45am 
     285      assert_equal Time.local(2005,10,30,0,45,0), Time.local(2005,10,31,0,45,0).yesterday, 'st-1.day=>dt' 
     286      assert_equal Time.local(2005,10, 31,0,45,0), Time.local(2005,11,1,0,45,0).yesterday, 'st-1.day=>st' 
     287    end 
     288    with_env_tz 'NZ' do 
     289      # dt: New Zealand: 2006 March 19th 1:45am 
     290      assert_equal Time.local(2006,3,19,1,45,0), Time.local(2006,3,20,1,45,0).yesterday, 'st-1.day=>dt' 
     291      assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,21,1,45,0).yesterday, 'st-1.day=>st' 
    240292    end 
    241293  end