php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77145 Inconsistent handle of negative interval lower than 1 second
Submitted: 2018-11-13 12:46 UTC Modified: 2018-11-13 13:42 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: kylekatarnls at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: Date/time related
PHP Version: 7.3.0RC5 OS:
Private report: No CVE-ID: None
 [2018-11-13 12:46 UTC] kylekatarnls at gmail dot com
Description:
------------
When calling DateTime::diff from (DateX) to (DateX - few microseconds), I get inconsistent intervals between versions and none are what I would expect (inverted interval with positive microseconds).

Test script:
---------------
$s = new DateTime('2018-10-11 20:59:06.914653');
$e = new DateTime('2018-10-11 20:59:06.237419');

echo $s->diff($e)->format('%R %Y-%M-%D %H:%I:%S.%F');

Expected result:
----------------
- 00-00-00 00:00:00.677234

Actual result:
--------------
Output for 7.3.0rc4 - 7.3.0rc5

+ -1-11-29 23:59:59.322766

Output for 7.1.0 - 7.3.0rc3

+ 00-00-00 00:00:00.-677234

As tested with https://3v4l.org/hnnL0

Note sure, but I guess 7.2.12 would looks like 7.3.0rc5 as it's probably consecutive to https://bugs.php.net/bug.php?id=77007 bugfix

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-13 13:42 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2018-11-13 13:42 UTC] cmb@php.net
This looks like a duplicate of bug #77097.
 [2018-11-13 14:15 UTC] kylekatarnls at gmail dot com
Yes it may be the same.

I would add, if we pass $absolute = TRUE, we still get the negative result.
 [2018-12-05 09:28 UTC] daszwarc at olx dot pl
PHP 7.2.12 is also affected
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Apr 21 21:01:24 2021 UTC