diff --git a/lib/tzinfo/timezone_proxy.rb b/lib/tzinfo/timezone_proxy.rb index 03ad7a9f..2124849d 100644 --- a/lib/tzinfo/timezone_proxy.rb +++ b/lib/tzinfo/timezone_proxy.rb @@ -82,7 +82,13 @@ def real_timezone # calculated multiple times in concurrently executing threads. It is not # worth the overhead of locking to ensure that @real_timezone is only # calculated once. - @real_timezone ||= Timezone.get(@identifier) + unless @real_timezone + result = Timezone.get(@identifier) + return result if frozen? + @real_timezone = result + end + + @real_timezone end end end diff --git a/test/tc_timezone_proxy.rb b/test/tc_timezone_proxy.rb index f176bfec..56292304 100644 --- a/test/tc_timezone_proxy.rb +++ b/test/tc_timezone_proxy.rb @@ -102,6 +102,15 @@ def test_canonical_linked end end + def test_after_freeze + proxy = TimezoneProxy.new('Europe/London') + real = Timezone.get('Europe/London') + t = Time.utc(2017, 6, 1) + proxy.freeze + assert_equal('Europe/London', proxy.identifier) + assert_equal(real.utc_to_local(t), proxy.utc_to_local(t)) + end + def test_equals assert_equal(true, TimezoneProxy.new('Europe/London') == TimezoneProxy.new('Europe/London')) assert_equal(false, TimezoneProxy.new('Europe/London') == TimezoneProxy.new('Europe/Paris'))