From 607a6c7a9a6fb3d8bd7d08d0307018b626105d83 Mon Sep 17 00:00:00 2001 From: Thomas Balthazar Date: Sat, 1 Oct 2016 13:26:15 +0200 Subject: 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 --- activesupport/lib/active_support/time_with_zone.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index c35588fbae..bee481e5f5 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -80,7 +80,8 @@ module ActiveSupport # Returns a Time instance of the simultaneous time in the system timezone. def localtime(utc_offset = nil) - @localtime ||= utc.getlocal(utc_offset) + @localtime ||= {} + @localtime[utc_offset] ||= utc.getlocal(utc_offset) end alias_method :getlocal, :localtime -- cgit v1.2.3