php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76822 DateTime mircoseconds rounding issue
Submitted: 2018-08-30 20:01 UTC Modified: 2020-09-01 14:03 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: jamesin dot hongkong dot 1 at gmail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 7.2.9 OS: any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-08-30 20:01 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-01 14:03 UTC] 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.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Oct 25 02:01:24 2020 UTC