diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2008-03-17 02:40:28 +0000 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2008-03-17 02:40:28 +0000 |
commit | 77ee522bf6c97352485fad3b72866f7ab424ecaf (patch) | |
tree | ae6684b38fce4c18cc46e4103f32cee92f8fc1da /activesupport/test/core_ext | |
parent | 1b41178a836ae84cf62a11ebd6bd640fd0d09566 (diff) | |
download | rails-77ee522bf6c97352485fad3b72866f7ab424ecaf.tar.gz rails-77ee522bf6c97352485fad3b72866f7ab424ecaf.tar.bz2 rails-77ee522bf6c97352485fad3b72866f7ab424ecaf.zip |
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
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 25 |
1 files changed, 25 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 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 |