diff options
author | Thomas Balthazar <thomas@balthazar.info> | 2016-10-01 13:26:15 +0200 |
---|---|---|
committer | Thomas Balthazar <thomas@balthazar.info> | 2016-10-01 13:38:43 +0200 |
commit | 607a6c7a9a6fb3d8bd7d08d0307018b626105d83 (patch) | |
tree | 2b5362469256acead3d6c45edfa2e60aadd66df5 /activesupport/test | |
parent | 268a5bb010ef91880d9b03b60e5e86ae5521e73c (diff) | |
download | rails-607a6c7a9a6fb3d8bd7d08d0307018b626105d83.tar.gz rails-607a6c7a9a6fb3d8bd7d08d0307018b626105d83.tar.bz2 rails-607a6c7a9a6fb3d8bd7d08d0307018b626105d83.zip |
Fix `ActiveSupport::TimeWithZone#localtime`
Previously memoization in `localtime` wasn't taking the `utc_offset`
parameter into account when returning a cached value. It now caches the
computed value depending on the `utc_offset` parameter, e.g:
Time.zone = "US/Eastern"
t = Time.zone.local(2016,5,2,11)
# => Mon, 02 May 2016 11:00:00 EDT -04:00
t.localtime(-7200)
# => 2016-05-02 13:00:00 -0200
t.localtime(-3600)
# => 2016-05-02 14:00:00 -0100
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 6 |
1 files changed, 6 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 e35aa6e154..5c940da1e3 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -54,6 +54,12 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_instance_of Time, @dt_twz.localtime end + def test_localtime_with_offset + assert_equal 0, @twz.localtime.gmt_offset + assert_equal (-3600), @twz.localtime(-3600).gmt_offset + assert_equal (-7200), @twz.localtime(-7200).gmt_offset + end + def test_utc? assert_equal false, @twz.utc? |