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

Fix double to microseconds conversion in ext/date. #14357

Closed
wants to merge 1 commit into from

Conversation

ranvis
Copy link
Contributor

@ranvis ranvis commented May 29, 2024

As mentioned by @kylekatarnls in #14332 (comment), php_date_initialize_from_ts_double() doesn't handle the fractional part of a double in the way users would expect.

var_dump(DateTime::createFromTimestamp(1599828571.235612)); // => ...235611

Also for example, 1.000_001 (1.000_000_99999999991773...) is transformed to @1.000000.

The updated code calculates the delta between the provided value and the next double value (in the case above, 1.000_001_00000000013978...), and if the delta is less than or equal to 0.5 microseconds, it uses the next value.
I think this solves the problem while keeping the original results on other cases.

CC: @marc-mabe

Use the next value of timestamp if the delta is less than or equal to
0.5 microseconds, to address numerical errors around exact microseconds.
@ranvis
Copy link
Contributor Author

ranvis commented May 31, 2024

Closing as per #14375.

@ranvis ranvis closed this May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant