aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md22
-rw-r--r--activesupport/lib/active_support/core_ext/date_and_time/compatibility.rb6
-rw-r--r--activesupport/lib/active_support/deprecation/instance_delegator.rb13
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb3
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb6
5 files changed, 19 insertions, 31 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 499310975e..f840783059 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,25 +1,3 @@
-* Fix `ActiveSupport::TimeWithZone#localtime` when called with different
- `utc_offset` values.
-
- 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
-
- Fixes #26644.
-
- *Thomas Balthazar*
-
* Fix `ActiveSupport::TimeWithZone#in` across DST boundaries.
Previously calls to `in` were being sent to the non-DST aware
diff --git a/activesupport/lib/active_support/core_ext/date_and_time/compatibility.rb b/activesupport/lib/active_support/core_ext/date_and_time/compatibility.rb
index 3f4e236ab7..db95ae0db5 100644
--- a/activesupport/lib/active_support/core_ext/date_and_time/compatibility.rb
+++ b/activesupport/lib/active_support/core_ext/date_and_time/compatibility.rb
@@ -12,7 +12,11 @@ module DateAndTime
mattr_accessor(:preserve_timezone, instance_writer: false) { false }
def to_time
- preserve_timezone ? getlocal(utc_offset) : getlocal
+ if preserve_timezone
+ @_to_time_with_instance_offset ||= getlocal(utc_offset)
+ else
+ @_to_time_with_system_offset ||= getlocal
+ end
end
end
end
diff --git a/activesupport/lib/active_support/deprecation/instance_delegator.rb b/activesupport/lib/active_support/deprecation/instance_delegator.rb
index 8efa6aabdc..6d390f3b37 100644
--- a/activesupport/lib/active_support/deprecation/instance_delegator.rb
+++ b/activesupport/lib/active_support/deprecation/instance_delegator.rb
@@ -6,6 +6,7 @@ module ActiveSupport
module InstanceDelegator # :nodoc:
def self.included(base)
base.extend(ClassMethods)
+ base.singleton_class.prepend(OverrideDelegators)
base.public_class_method :new
end
@@ -19,6 +20,18 @@ module ActiveSupport
singleton_class.delegate(method_name, to: :instance)
end
end
+
+ module OverrideDelegators # :nodoc:
+ def warn(message = nil, callstack = nil)
+ callstack ||= caller_locations(2)
+ super
+ end
+
+ def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil)
+ caller_backtrace ||= caller_locations(2)
+ super
+ end
+ end
end
end
end
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index bee481e5f5..8de8120fba 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -80,8 +80,7 @@ module ActiveSupport
# Returns a <tt>Time</tt> instance of the simultaneous time in the system timezone.
def localtime(utc_offset = nil)
- @localtime ||= {}
- @localtime[utc_offset] ||= utc.getlocal(utc_offset)
+ utc.getlocal(utc_offset)
end
alias_method :getlocal, :localtime
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 5c940da1e3..e35aa6e154 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -54,12 +54,6 @@ 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?