[php-src] PR #14357: Fix double to microseconds conversion in ext/date.
| From: | ranvis | Date: | Wed, 29 May 2024 10:47:26 +0000 |
| Subject: | [php-src] PR #14357: Fix double to microseconds conversion in ext/date. | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-26364@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/14357
Author: ranvis
As mentioned by @kylekatarnls in <https://github.com/php/php-src/issues/14332#issuecomment-2132794556>,
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