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

Changeset 9213

Show
Ignore:
Timestamp:
04/02/08 14:15:30 (4 months ago)
Author:
gbuesing
Message:

TimeWithZone: Adding tests for dst and leap day edge cases when advancing time

Files:

Legend:

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

    r9210 r9213  
    11*SVN* 
     2 
     3* TimeWithZone: Adding tests for dst and leap day edge cases when advancing time [Geoff Buesing] 
    24 
    35* TimeWithZone#method_missing: send to utc to advance with dst correctness, otherwise send to time. Adding tests for time calculations methods [Geoff Buesing] 
  • trunk/activesupport/test/core_ext/time_with_zone_test.rb

    r9208 r9213  
    457457    assert_equal 19 * 60 * 60, @twz.seconds_since_midnight 
    458458  end 
     459   
     460  def test_advance_1_year_from_leap_day 
     461    twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2004,2,29)) 
     462    assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(:years => 1).inspect 
     463    assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.years_since(1).inspect 
     464    assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", (twz + 1.year).inspect 
     465  end 
     466   
     467  def test_advance_1_month_from_last_day_of_january 
     468    twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2005,1,31)) 
     469    assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(:months => 1).inspect 
     470    assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.months_since(1).inspect 
     471    assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", (twz + 1.month).inspect 
     472  end 
     473   
     474  def test_advance_1_month_from_last_day_of_january_during_leap_year 
     475    twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2000,1,31)) 
     476    assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.advance(:months => 1).inspect 
     477    assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.months_since(1).inspect 
     478    assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", (twz + 1.month).inspect 
     479  end 
     480   
     481  def test_advance_1_month_into_spring_dst_gap 
     482    twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,3,2,2)) 
     483    assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(:months => 1).inspect 
     484    assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.months_since(1).inspect 
     485    assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", (twz + 1.month).inspect 
     486  end 
     487   
     488  def test_advance_1_second_into_spring_dst_gap 
     489    twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,2,1,59,59)) 
     490    assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(:seconds => 1).inspect 
     491    assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", (twz + 1).inspect 
     492    assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", (twz + 1.second).inspect 
     493  end 
    459494end 
    460495