Bug #77097 [Com]: DateTime::diff gives wrong diff when the actual diff is less than 1 second

From: Date: Fri, 09 Nov 2018 06:04:01 +0000
Subject: Bug #77097 [Com]: DateTime::diff gives wrong diff when the actual diff is less than 1 second
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217878@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77097&edit=1 ID: 77097 Comment by: sakari dot laine at verkkokauppa dot com Reported by: vishnunn at ymail dot com Summary: DateTime::diff gives wrong diff when the actual diff is less than 1 second Status: Verified Type: Bug Package: Date/time related Operating System: CentOS Linux 7.5.1804 PHP Version: 7.3.0RC4 Assigned To: derick Block user comment: N Private report: N New Comment: Affects also 7.2.12 Previous Comments: ------------------------------------------------------------------------ [2018-11-08 09:55:53] cmb@php.net Related To: Bug #77121 ------------------------------------------------------------------------ [2018-11-03 12:21:15] cmb@php.net 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? ------------------------------------------------------------------------ [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

« previous php.bugs (#217878) next »