From 52b57c662c129d72d44fa1ab9920a752c1973482 Mon Sep 17 00:00:00 2001 From: Geoff Buesing Date: Tue, 11 Mar 2008 04:26:20 +0000 Subject: TimeWithZone instances correctly enforce DST rules. Adding TimeZone#period_for_utc git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9006 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/core_ext/time_with_zone_test.rb | 43 ++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'activesupport/test/core_ext') diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index c7b71f4ffe..74fbc56595 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -165,6 +165,38 @@ uses_tzinfo 'TimeWithZoneTest' do assert_equal 86_400.0, twz2 - twz1 end + def test_plus_and_minus_enforce_spring_dst_rules + utc = Time.utc(2006,4,2,6,59,59) # == Apr 2 2006 01:59:59 EST; i.e., 1 second before daylight savings start + twz = ActiveSupport::TimeWithZone.new(utc, @time_zone) + assert_equal Time.utc(2006,4,2,1,59,59), twz.time + assert_equal false, twz.dst? + assert_equal 'EST', twz.zone + twz = twz + 1 + assert_equal Time.utc(2006,4,2,3), twz.time # adding 1 sec springs forward to 3:00AM EDT + assert_equal true, twz.dst? + assert_equal 'EDT', twz.zone + twz = twz - 1 # subtracting 1 second takes goes back to 1:59:59AM EST + assert_equal Time.utc(2006,4,2,1,59,59), twz.time + assert_equal false, twz.dst? + assert_equal 'EST', twz.zone + end + + def test_plus_and_minus_enforce_fall_dst_rules + utc = Time.utc(2006,10,29,5,59,59) # == Oct 29 2006 01:59:59 EST; i.e., 1 second before daylight savings end + twz = ActiveSupport::TimeWithZone.new(utc, @time_zone) + assert_equal Time.utc(2006,10,29,1,59,59), twz.time + assert_equal true, twz.dst? + assert_equal 'EDT', twz.zone + twz = twz + 1 + assert_equal Time.utc(2006,10,29,1), twz.time # adding 1 sec falls back from 1:59:59 EDT to 1:00AM EST + assert_equal false, twz.dst? + assert_equal 'EST', twz.zone + twz = twz - 1 + assert_equal Time.utc(2006,10,29,1,59,59), twz.time # subtracting 1 sec goes back to 1:59:59AM EDT + assert_equal true, twz.dst? + assert_equal 'EDT', twz.zone + end + def test_to_a assert_equal [45, 30, 5, 1, 2, 2000, 2, 32, false, "HST"], ActiveSupport::TimeWithZone.new( Time.utc(2000, 2, 1, 15, 30, 45), TimeZone['Hawaii'] ).to_a end @@ -219,9 +251,14 @@ uses_tzinfo 'TimeWithZoneTest' do end def test_method_missing_with_non_time_return_value - assert_equal 1999, @twz.year - assert_equal 12, @twz.month - assert_equal 31, @twz.day + twz = ActiveSupport::TimeWithZone.new(Time.utc(1999,12,31,19,18,17,500), @time_zone) + assert_equal 1999, twz.year + assert_equal 12, twz.month + assert_equal 31, twz.day + assert_equal 14, twz.hour + assert_equal 18, twz.min + assert_equal 17, twz.sec + assert_equal 500, twz.usec end end -- cgit v1.2.3