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-10-11 16:29 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: Closed Package: Date/time related
PHP Version: 7.2.0 OS: OSX
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: marcospassos dot com at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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
 [2018-10-11 15:59 UTC] derick@php.net
This is fixed for PHP 7.3.0RC4, by upgrading timelib (See: #75577)
 [2018-10-11 16:29 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2018-10-11 16:29 UTC] cmb@php.net
So this can be closed (I assume there will be no back-port of the
fix).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 02:01:28 2024 UTC