diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-07-09 15:40:59 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-07-09 15:40:59 +0100 |
commit | b775987e72260233c66080483b3c964f9549d094 (patch) | |
tree | 19103789c23b3bbbd791346d4351b2eb5a486efc /activesupport | |
parent | ccad803bf44fe30602a041ff0ab1cbe985bc3840 (diff) | |
download | rails-b775987e72260233c66080483b3c964f9549d094.tar.gz rails-b775987e72260233c66080483b3c964f9549d094.tar.bz2 rails-b775987e72260233c66080483b3c964f9549d094.zip |
Return local time for backwards compatibility
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG.md | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_ext_test.rb | 33 |
3 files changed, 27 insertions, 10 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 21a726bfc1..20579e44d3 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,6 +1,6 @@ ## unreleased ## -* Make `Time.at_with_coercion` retain the second fraction and offset from UTC. +* Make `Time.at_with_coercion` retain the second fraction and return local time. Fixes #11350 diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 9663edb0ad..0383a6a963 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -55,7 +55,7 @@ class Time time_or_number = args.first if time_or_number.is_a?(ActiveSupport::TimeWithZone) || time_or_number.is_a?(DateTime) - at_without_coercion(time_or_number.to_f).getlocal(time_or_number.utc_offset) + at_without_coercion(time_or_number.to_f).getlocal else at_without_coercion(time_or_number) end diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 57ead2edc5..2a9d059d58 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -785,9 +785,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 @@ -802,10 +811,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 @@ -816,20 +833,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 |