Bug #77235 [NEW]: DateTime::diff Wrong result if subsecond difference
| From: | arkham dot vm at gmail dot com | Date: | Tue, 04 Dec 2018 06:23:08 +0000 |
| Subject: | Bug #77235 [NEW]: DateTime::diff Wrong result if subsecond difference | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-218260@lists.php.net to get a copy of this message | ||
From: arkham dot vm at gmail dot com
Operating system: CentOs 7.5
PHP version: 7.2.12
Package: *General Issues
Bug Type: Bug
Bug description:DateTime::diff Wrong result if subsecond difference
Description:
------------
If diffirence between two dates less than second,
DateTime::diff
returns more than 1 year of difference.
date_diff contains same bug.
Works properly on:
PHP 7.2.10-0ubuntu1 (cli) (built: Sep 13 2018 13:38:55) ( NTS )
Bugged on:
PHP 7.2.12 (cli) (built: Nov 6 2018 16:40:25) ( NTS )
Test script:
---------------
<?php
$utc = new DateTimeZone('utc');
$foo = new DateTime('2018-11-29 07:14:12.503985', $utc);
$bar = new DateTime('2018-11-29 07:14:12.000000', $utc);
print_r($foo->diff($bar));
Expected result:
----------------
DateInterval Object
(
[y] => 0
[m] => 0
[d] => 0
[h] => 0
[i] => 0
[s] => 0
[f] => -0.503985
[weekday] => 0
[weekday_behavior] => 0
[first_last_day_of] => 0
[invert] => 0
[days] => 0
[special_type] => 0
[special_amount] => 0
[have_weekday_relative] => 0
[have_special_relative] => 0
)
Actual result:
--------------
DateInterval Object
(
[y] => -1
[m] => 11
[d] => 30
[h] => 23
[i] => 59
[s] => 59
[f] => 0.496015
[weekday] => 0
[weekday_behavior] => 0
[first_last_day_of] => 0
[invert] => 0
[days] => 0
[special_type] => 0
[special_amount] => 0
[have_weekday_relative] => 0
[have_special_relative] => 0
)
--
Edit bug report at https://bugs.php.net/bug.php?id=77235&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77235&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77235&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77235&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77235&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77235&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77235&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77235&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77235&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77235&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77235&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77235&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77235&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77235&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77235&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77235&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77235&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77235&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77235&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77235&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77235&r=mysqlcfg