Bug #76822 [Opn->Nab]: DateTime mircoseconds rounding issue
Edit report at https://bugs.php.net/bug.php?id=76822&edit=1
ID: 76822
Updated by: derick@php.net
Reported by: jamesin dot hongkong dot 1 at gmail dot com
Summary: DateTime mircoseconds rounding issue
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: any
PHP Version: 7.2.9
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP --
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php
If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.
This got fixed in PHP 7.2.0
Previous Comments:
------------------------------------------------------------------------
[2020-09-01 14:03:41] cmb@php.net
As of PHP 7.2.0, the microseconds are no longer stored as doubles,
but rather as integers. Apparently, when parsing the
microseconds, these are just truncated to six decimal places.
------------------------------------------------------------------------
[2018-08-30 20:01:38] jamesin dot hongkong dot 1 at gmail dot com
Description:
------------
Some of our integration tests suddenly fail on PHP7.2+ due to a rounding issue in regards to
DateTime/microseconds.
## Reproducible example
```
Output for hhvm-3.18.5 - 3.22.0, 7.2.0 - 7.3.0beta2
2011-01-01 15:03:01.888499
Output for 5.6.30, 7.0.28 - 7.1.21
2011-01-01 15:03:01.888500
```
https://3v4l.org/al15I
Test script:
---------------
$d = new DateTime('2011-01-01T15:03:01.88849994Z');
print $d->format( 'Y-m-d H:i:s.u' );
Expected result:
----------------
2011-01-01 15:03:01.888500
Actual result:
--------------
2011-01-01 15:03:01.888499
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76822&edit=1
Thread (3 messages)