Skip to content
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

Calculate travel_offset to align with the precision of argument to Timecop.travel #421

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

dgholz
Copy link

@dgholz dgholz commented May 14, 2024

Subtracting two Times returns a Float, which may not be accurate down to subsecond resolution. Because Floats are stored as double-precision values (IEEE 754), they can have resolutions much higher than the typical minimum clock precision of 10e-9 seconds. Which can result in two Time object not comparing as equal when they are the same down to the nanosecond, when one has had a travel_offset applied to it.

To fix #420.

Subtracting two `Time`s returns a `Float`, which may not be accurate
down to subsecond resolution. Because `Float`s are stored as double-
precision values (IEEE 754), they can have resolutions much higher than
the typical minimum clock precision of 10e-9 seconds. Which can result
in two `Time` object not comparing as equal when they are the same down
to the nanosecond, when one has had a travel_offset applied to it.
@dgholz dgholz force-pushed the align_subsec_on_nanoseconds branch from 5dcbc68 to 2906ca3 Compare June 27, 2024 11:22
@dgholz dgholz changed the title Calculate travel_offset to align with clock precision Calculate travel_offset to align with the precision of the argument to Timecop.travel Jun 27, 2024
@dgholz dgholz changed the title Calculate travel_offset to align with the precision of the argument to Timecop.travel Calculate travel_offset to align with the precision of argument to Timecop.travel Jun 27, 2024
@dgholz dgholz force-pushed the align_subsec_on_nanoseconds branch from 2906ca3 to c2bdfc7 Compare June 27, 2024 11:41
@dgholz
Copy link
Author

dgholz commented Jul 11, 2024

@joshuacronemeyer I'd greatly appreciate your opinion on this PR, if you have the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Time.now sometimes has greater-than-nanosecond precision when called under Timecop.travel
1 participant