Skip to content

Commit

Permalink
Don't store @real_timezone if the instance has been frozen.
Browse files Browse the repository at this point in the history
See #80.
  • Loading branch information
philr committed Jan 27, 2018
1 parent 2a9459c commit 939d306
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/tzinfo/timezone_proxy.rb
Expand Up @@ -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
9 changes: 9 additions & 0 deletions test/tc_timezone_proxy.rb
Expand Up @@ -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'))
Expand Down

0 comments on commit 939d306

Please sign in to comment.