aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/time_ext_test.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2013-07-09 15:50:14 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2013-07-09 15:50:14 +0100
commitc42260a3251157070a1bafadd179e4441df8933e (patch)
tree8956fc1318447c30a75305a829d7050d62a0b130 /activesupport/test/core_ext/time_ext_test.rb
parent37d1e48dfe1d120053ea71090cd52314990b4978 (diff)
downloadrails-c42260a3251157070a1bafadd179e4441df8933e.tar.gz
rails-c42260a3251157070a1bafadd179e4441df8933e.tar.bz2
rails-c42260a3251157070a1bafadd179e4441df8933e.zip
Return local time for backwards compatibility
Diffstat (limited to 'activesupport/test/core_ext/time_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb33
1 files changed, 25 insertions, 8 deletions
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index 63fddd0cfd..8741f033b5 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -700,9 +700,18 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
end
end
- def test_at_with_datetime_maintains_offset
+ def test_at_with_datetime_returns_local_time
with_env_tz 'US/Eastern' do
- assert_equal 3600, Time.at(DateTime.civil(2000, 1, 1, 0, 0, 0, '+1')).utc_offset
+ dt = DateTime.civil(2000, 1, 1, 0, 0, 0, '+0')
+ assert_equal Time.local(1999, 12, 31, 19, 0, 0), Time.at(dt)
+ assert_equal 'EST', Time.at(dt).zone
+ assert_equal(-18000, Time.at(dt).utc_offset)
+
+ # Daylight savings
+ dt = DateTime.civil(2000, 7, 1, 1, 0, 0, '+1')
+ assert_equal Time.local(2000, 6, 30, 20, 0, 0), Time.at(dt)
+ assert_equal 'EDT', Time.at(dt).zone
+ assert_equal(-14400, Time.at(dt).utc_offset)
end
end
@@ -717,10 +726,18 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
end
end
- def test_at_with_time_with_zone_maintains_offset
+ def test_at_with_time_with_zone_returns_local_time
with_env_tz 'US/Eastern' do
- assert_equal 0, Time.at(ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['London'])).utc_offset
- assert_equal 3600, Time.at(ActiveSupport::TimeWithZone.new(Time.utc(2000, 7, 1, 0, 0, 0), ActiveSupport::TimeZone['London'])).utc_offset
+ twz = ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['London'])
+ assert_equal Time.local(1999, 12, 31, 19, 0, 0), Time.at(twz)
+ assert_equal 'EST', Time.at(twz).zone
+ assert_equal(-18000, Time.at(twz).utc_offset)
+
+ # Daylight savings
+ twz = ActiveSupport::TimeWithZone.new(Time.utc(2000, 7, 1, 0, 0, 0), ActiveSupport::TimeZone['London'])
+ assert_equal Time.local(2000, 6, 30, 20, 0, 0), Time.at(twz)
+ assert_equal 'EDT', Time.at(twz).zone
+ assert_equal(-14400, Time.at(twz).utc_offset)
end
end
@@ -731,20 +748,20 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
def test_at_with_utc_time
with_env_tz 'US/Eastern' do
assert_equal Time.utc(2000), Time.at(Time.utc(2000))
- assert_equal 0, Time.at(Time.utc(2000)).utc_offset
assert_equal 'UTC', Time.at(Time.utc(2000)).zone
+ assert_equal(0, Time.at(Time.utc(2000)).utc_offset)
end
end
def test_at_with_local_time
with_env_tz 'US/Eastern' do
assert_equal Time.local(2000), Time.at(Time.local(2000))
- assert_equal -18000, Time.at(Time.local(2000)).utc_offset
assert_equal 'EST', Time.at(Time.local(2000)).zone
+ assert_equal(-18000, Time.at(Time.local(2000)).utc_offset)
assert_equal Time.local(2000, 7, 1), Time.at(Time.local(2000, 7, 1))
- assert_equal -14400, Time.at(Time.local(2000, 7, 1)).utc_offset
assert_equal 'EDT', Time.at(Time.local(2000, 7, 1)).zone
+ assert_equal(-14400, Time.at(Time.local(2000, 7, 1)).utc_offset)
end
end