Bug #77097 [Opn->Ver]: DateTime::diff gives wrong diff when the actual diff is less than 1 second
Edit report at https://bugs.php.net/bug.php?id=77097&edit=1
ID: 77097
Updated by: cmb@php.net
Reported by: vishnunn at ymail dot com
Summary: DateTime::diff gives wrong diff when the actual diff
is less than 1 second
-Status: Open
+Status: Verified
Type: Bug
Package: Date/time related
Operating System: CentOS Linux 7.5.1804
PHP Version: 7.3.0RC4
-Assigned To:
+Assigned To: derick
Block user comment: N
Private report: N
New Comment:
I can confirm a behavioral change, albeit I get a slightly
different result with PHP-7.3 (@9afce01), where 'f' is
float(0.218249). This would basically still be somehow correct,
but if I request an $absolute result, I still get an identical
result, which is certainly not correct.
Derick, could you please have a look at this?
Previous Comments:
------------------------------------------------------------------------
[2018-11-03 11:59:17] vishnunn at ymail dot com
Description:
------------
---
From manual page: https://php.net/datetime.diff
---
Test script:
---------------
$now = new DateTime('2018-11-03 11:34:20.781751');
$ago = new DateTime('2018-11-03 11:34:20.000000');
$diff = $now->diff($ago);
var_dump($diff);
Expected result:
----------------
On PHPv7.2.11 it gives the correct output:
Date/time in $now: 2018-11-03 11:34:20.781751
Date/time in $ago: 2018-11-03 11:34:20.000000
object(DateInterval)#574 (16) {
["y"]=>
int(0)
["m"]=>
int(0)
["d"]=>
int(0)
["h"]=>
int(0)
["i"]=>
int(0)
["s"]=>
int(0)
["f"]=>
float(-0.781751)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(0)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
Actual result:
--------------
On PHPv7.3RC4 it give this output which is wrong:
Date/time in $now: 2018-11-03 11:50:50.826351
Date/time in $ago: 2018-11-03 11:50:50.000000
object(DateInterval)#574 (16) {
["y"]=>
int(-1)
["m"]=>
int(11)
["d"]=>
int(30)
["h"]=>
int(23)
["i"]=>
int(59)
["s"]=>
int(59)
["f"]=>
float(0.173649)
["weekday"]=>
int(0)
["weekday_behavior"]=>
int(0)
["first_last_day_of"]=>
int(0)
["invert"]=>
int(0)
["days"]=>
int(0)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77097&edit=1
Thread (8 messages)