-
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
Time.change doesn't support changing nanoseconds #16392
Comments
Note: use of Time#change in the above monkey patch is just an implementation detail, I believe I originally implemented this differently before I discovered the #change method and updated my implementation to the above as it was cleaner. This is just an example that demonstrates a use case for being able to pass an |
Whilst we should probably add support for a
|
That's a useful workaround, thanks. |
Tangentially related to your original problem, time travel helpers now always truncate the @pixeltrix do you still plan to add this in 4.2? It is currently listed in the github milestone, so it would block 4.2.0.rc1. |
@chancancode just back from holiday so I've got a few tickets to go through over the next few days |
@pixeltrix no worries, but I just want to know if we want/need to hold the release for this 😄 |
@pixeltrix I removed the milestone since this doesn't seem super critical. If it ends up making it into 4.2, great, otherwise it's not the end of the world. Feel free to change it back if you feel otherwise :) |
I previously encountered an issue in my tests where I would be comparing a Ruby date with a date returned by ActiveRecord and the comparison would fail because the date returned from the database would lose its nanosecond precision.
My workaround was to use Timecop and the Rails #change method to freeze to a given time with truncated nanoseconds, using this small monkey patch:
This worked in Rails 3 and no longer works in Rails 4. On further investigation, it appears that Time#change doesn't actually support the
nsec
key (hence this issue) - my fix only worked by accident because Time#change truncated nanoseconds.This was reported as #9591 and fixed in Rails 4, so Time#change now preserves nanoseconds but there is still no support for changing the nanoseconds.
The text was updated successfully, but these errors were encountered: