From 77ee522bf6c97352485fad3b72866f7ab424ecaf Mon Sep 17 00:00:00 2001 From: Geoff Buesing Date: Mon, 17 Mar 2008 02:40:28 +0000 Subject: TimeWithZone caches TZInfo::TimezonePeriod used for time conversion so that it can be reused, and enforces DST rules correctly when instance is created from a local time git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9040 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/core_ext/time_with_zone_test.rb | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'activesupport/test/core_ext/time_with_zone_test.rb') diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index a3566796a7..5f1a002071 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -256,6 +256,31 @@ uses_tzinfo 'TimeWithZoneTest' do assert_equal 17, twz.sec assert_equal 500, twz.usec end + + def test_utc_to_local_conversion_saves_period_in_instance_variable + assert_nil @twz.instance_variable_get('@period') + @twz.time + assert_kind_of TZInfo::TimezonePeriod, @twz.instance_variable_get('@period') + end + + def test_instance_created_with_local_time_returns_correct_utc_time + twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(1999, 12, 31, 19)) + assert_equal Time.utc(2000), twz.utc + end + + def test_instance_created_with_local_time_enforces_spring_dst_rules + twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,2,2)) # first second of DST + assert_equal Time.utc(2006,4,2,3), twz.time # springs forward to 3AM + assert_equal true, twz.dst? + assert_equal 'EDT', twz.zone + end + + def test_instance_created_with_local_time_enforces_fall_dst_rules + twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,10,29,1)) # 1AM can be either DST or non-DST; we'll pick DST + assert_equal Time.utc(2006,10,29,1), twz.time + assert_equal true, twz.dst? + assert_equal 'EDT', twz.zone + end end class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase -- cgit v1.2.3