-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ActiveSupport::TimeWithZone#localtime
#26677
Conversation
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
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
@tbalthazar thanks! 👍 |
Backported to 5-0-stable in f7e9f1a - the fix I made for 4-2-stable to address the original performance issue isn't affected because it just caches |
@@ -54,6 +54,12 @@ def test_localtime | |||
assert_instance_of Time, @dt_twz.localtime | |||
end | |||
|
|||
def test_localtime_with_offset | |||
assert_equal 0, @twz.localtime.gmt_offset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pixeltrix this isn't passing for me
1) Failure:
TimeWithZoneTest#test_localtime_with_offset [test/core_ext/time_with_zone_test.rb:58]:
Expected: 0
Actual: 37800
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build was green - hmm. What timezone are you in?
Summary
Fix
ActiveSupport::TimeWithZone#localtime
when called with differentutc_offset
values.Previously memoization in
localtime
wasn't taking theutc_offset
parameter into account when returning a cached value. It now caches the computed value depending on theutc_offset
parameter, e.g:Fixes #26644.