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: 2021-04-06 18:42 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: jamesin dot hongkong dot 1 at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 7.2.9 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jamesin dot hongkong dot 1 at gmail dot com
New email:
PHP Version: OS:

 

 [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.
 [2021-04-06 18:42 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2021-04-06 18:42 UTC] derick@php.net
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 10:01:31 2024 UTC