diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2008-04-02 14:15:30 +0000 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2008-04-02 14:15:30 +0000 |
commit | 2c6f1d43962796558301528e2c9ff40e53f01409 (patch) | |
tree | cf7c5c829113bc0fab875c6fed5541958c7dab27 /activesupport/test/core_ext | |
parent | 1e087fd3fd0d6c0b839ab6c15982a996a5d4d531 (diff) | |
download | rails-2c6f1d43962796558301528e2c9ff40e53f01409.tar.gz rails-2c6f1d43962796558301528e2c9ff40e53f01409.tar.bz2 rails-2c6f1d43962796558301528e2c9ff40e53f01409.zip |
TimeWithZone: Adding tests for dst and leap day edge cases when advancing time
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9213 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 7658c4a562..5cebfae583 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -456,6 +456,41 @@ class TimeWithZoneTest < Test::Unit::TestCase def test_seconds_since_midnight assert_equal 19 * 60 * 60, @twz.seconds_since_midnight end + + def test_advance_1_year_from_leap_day + twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2004,2,29)) + assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(:years => 1).inspect + assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.years_since(1).inspect + assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", (twz + 1.year).inspect + end + + def test_advance_1_month_from_last_day_of_january + twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2005,1,31)) + assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(:months => 1).inspect + assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.months_since(1).inspect + assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", (twz + 1.month).inspect + end + + def test_advance_1_month_from_last_day_of_january_during_leap_year + twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2000,1,31)) + assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.advance(:months => 1).inspect + assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.months_since(1).inspect + assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", (twz + 1.month).inspect + end + + def test_advance_1_month_into_spring_dst_gap + twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,3,2,2)) + assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(:months => 1).inspect + assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.months_since(1).inspect + assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", (twz + 1.month).inspect + end + + def test_advance_1_second_into_spring_dst_gap + twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,2,1,59,59)) + assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(:seconds => 1).inspect + assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", (twz + 1).inspect + assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", (twz + 1.second).inspect + end end class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase |