aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/time_with_zone_test.rb
diff options
context:
space:
mode:
authorGeoff Buesing <gbuesing@gmail.com>2008-03-17 02:40:28 +0000
committerGeoff Buesing <gbuesing@gmail.com>2008-03-17 02:40:28 +0000
commit77ee522bf6c97352485fad3b72866f7ab424ecaf (patch)
treeae6684b38fce4c18cc46e4103f32cee92f8fc1da /activesupport/test/core_ext/time_with_zone_test.rb
parent1b41178a836ae84cf62a11ebd6bd640fd0d09566 (diff)
downloadrails-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/time_with_zone_test.rb')
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb25
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