php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75642 Wrap around behaviour for microseconds is not working
Submitted: 2017-12-06 22:11 UTC Modified: 2018-04-23 14:21 UTC
Votes:4
Avg. Score:3.8 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:0 (0.0%)
From: marcospassos dot com at gmail dot com Assigned: derick (profile)
Status: Verified Package: Date/time related
PHP Version: 7.2.0 OS: OSX
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-12-06 22:11 UTC] marcospassos dot com at gmail dot com
Description:
------------
When adding 1 microsecond to 999999 does not increment the seconds part.

Test script:
---------------
// https://3v4l.org/Wl6if
$date = new \DateTime('2017-12-31 23:59:59.999999');

echo $date->format('Y-m-d H:i:s.u');
echo "\n";
echo $date->modify('+1 microsecond')->format('Y-m-d H:i:s.u');

Expected result:
----------------
2017-12-31 23:59:59.999999
2016-01-01 00:00:00.000000

Actual result:
--------------
2017-12-31 23:59:59.999999
2017-12-31 23:59:59.1000000

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-06 22:12 UTC] marcospassos dot com at gmail dot com
Expected result:
----------------
2017-12-31 23:59:59.999999
2018-01-01 00:00:00.000000
 [2017-12-06 22:26 UTC] spam2 at rhsoft dot net
pretty sure the sad float precision problem which makes me wonder why it's called computer and not guesser
 [2018-01-21 19:12 UTC] marcospassos dot com at gmail dot com
Any update about this issue?
 [2018-03-09 12:06 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2018-03-09 12:06 UTC] cmb@php.net
> pretty sure the sad float precision problem

Apparently[1].  However, `2017-12-31 23:59:59.1000000` is wrong
nonetheless.

[1] <https://3v4l.org/e3utY>
 [2018-03-09 15:06 UTC] requinix@php.net
Microseconds are actually their own distinct integer.

Off by one error.
https://github.com/php/php-src/blob/PHP-7.2.0/ext/date/lib/tm2unixtime.c#L42

Additionally it's only able to over-/underflow the seconds by a change of 2.
https://3v4l.org/4Ra66
 [2018-04-23 14:21 UTC] cmb@php.net
-Assigned To: +Assigned To: derick
 [2018-04-23 14:21 UTC] cmb@php.net
I've filed a respective ticket upstream[1]:
<https://github.com/derickr/timelib/issues/35>.
 [2018-06-06 14:08 UTC] german dot drulyk at gmail dot com
Confirmed reproduce-able on:

Windows 7 x64
PHP x64 7.1.16 and 7.2.4
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Jul 16 10:01:53 2018 UTC