diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-11-05 22:29:11 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-11-05 22:29:11 +0000 |
commit | 47576a646bd99d431f4217b20b7625bdd3444171 (patch) | |
tree | 1e2912a07b1cf0458ddc090c37c67001f124b7ee /activesupport/test/core_ext/date_time_ext_test.rb | |
parent | 800b69b6adab2e2ea90b66fd2b37ed05f973b1d5 (diff) | |
download | rails-47576a646bd99d431f4217b20b7625bdd3444171.tar.gz rails-47576a646bd99d431f4217b20b7625bdd3444171.tar.bz2 rails-47576a646bd99d431f4217b20b7625bdd3444171.zip |
Cater for DST changes when converting Times to DateTimes. Closes #10068 [gbuesing]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8076 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/core_ext/date_time_ext_test.rb')
-rw-r--r-- | activesupport/test/core_ext/date_time_ext_test.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index f4d5427d0f..0f2c788926 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -35,8 +35,9 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase # FIXME: ruby 1.9 compat def test_to_time assert_equal Time.utc(2005, 2, 21, 10, 11, 12), DateTime.new(2005, 2, 21, 10, 11, 12, 0, 0).to_time - assert_equal Time.local(2005, 2, 21, 10, 11, 12), DateTime.new(2005, 2, 21, 10, 11, 12, Rational(-5, 24), 0).to_time assert_equal Time.utc_time(2039, 2, 21, 10, 11, 12), DateTime.new(2039, 2, 21, 10, 11, 12, 0, 0).to_time + # DateTimes with offsets other than 0 are returned unaltered + assert_equal DateTime.new(2005, 2, 21, 10, 11, 12, Rational(-5, 24)), DateTime.new(2005, 2, 21, 10, 11, 12, Rational(-5, 24)).to_time end def test_seconds_since_midnight @@ -211,4 +212,21 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase def test_acts_like_time assert DateTime.new.acts_like_time? end + + def test_local_offset + with_timezone 'US/Eastern' do + assert_equal Rational(-5, 24), DateTime.local_offset + end + with_timezone 'US/Central' do + assert_equal Rational(-6, 24), DateTime.local_offset + end + end + + protected + def with_timezone(new_tz = 'US/Eastern') + old_tz, ENV['TZ'] = ENV['TZ'], new_tz + yield + ensure + old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') + end end |