Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Allow Time#to_time on frozen objects. Return frozen time rather than "RuntimeError: can't modify frozen Time" #28147
In 29f211f memoization was added to
I have reverted the commit that adds this memoization. I added regression tests to cover the cases with frozen
In working through this problem and attempting to test it, I found that calling
I have fixed this by returning a frozen time if the original was frozen.
There is actually a more serious regression specifically and exclusively in
To answer my own question - it leaves the return Time instance as unfrozen and even doing this dance doesn't work:
def freeze_with_compatibiliy #:nodoc: to_time.freeze_without_compatibiliy freeze_without_compatibiliy end alias_method :freeze_without_compatibiliy, :freeze alias_method :freeze, :freeze_with_compatibiliy
Because it leaves the return from to_time frozen and not cached.
It was a heck of a slow down so I'm loathe to revert that without giving it some thought.
Hmm, not sure about the whole return the response of
Using this script I checked the behaviour across all the Ruby versions this needs to work against:
As you can see I think the frozen issue is a red herring - we just need to make sure that we return self and that will fix the problem. Given that I think it should be possible to cache the
@kmcphillips if you've not done anything yet then I have a solution which does the following:
This solution returns self where appropriate and still fixes the previous performance issue which was around comparing two
There may be additional performance gains by rewriting
@pixeltrix This is wonderful.
Yeah, you got further than me here. But doing
Part of what exposed this bug in
if other.class == Time compare_without_coercion(other)
And always falls back to
I was looking at how to essentially turn those tables above into tests to help prevent regressions.
I'd be happy to put this together this weekend and get tests covering all the cases, unless you're attached to doing it yourself. I'd be glad for the experience and to get a better understanding of date/time/zones. Always bugs to fix related to time in our apps.
referenced this pull request
Mar 1, 2017
I have 100% not forgotten! But I injured my shoulder and have been off work and computers in general for a week. This was and still is top of my pile, but if I'm not in better shape and able to pick it back up in the next few days, I'll bounce it to you.…
On Fri, Mar 3, 2017 at 5:03 AM Andrew White ***@***.***> wrote: @kmcphillips <https://github.com/kmcphillips> are you planning to work on this - if not I can pick it up — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#28147 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAFIv0uEAeoZWGTDhzEV7rnRgrOOZFnrks5rh-VQgaJpZM4MK4R7> .