Bug #77237 [NEW]: DateTime diff wrong when using milliseconds

From: Date: Tue, 04 Dec 2018 08:43:44 +0000
Subject: Bug #77237 [NEW]: DateTime diff wrong when using milliseconds
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218261@lists.php.net to get a copy of this message
From:             bstanescu at gmail dot com
Operating system: Ubuntu 16.0.4
PHP version:      7.2.12
Package:          Date/time related
Bug Type:         Bug
Bug description:DateTime diff wrong when using milliseconds

Description:
------------
DateTime diff method returns incorrect result when using milliseconds

This might be related to this fix introduced in 7.2.12:
https://bugs.php.net/bug.php?id=77007



Test script:
---------------
<?php

$diff = (new DateTime('2018-12-04T07:42:59.123Z'))->diff(new
DateTime('2018-12-04T07:42:59.122Z');

print_r($diff);

?>

Expected result:
----------------
DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 0
    [f] => -0.123
    [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] => 29
    [h] => 23
    [i] => 59
    [s] => 59
    [f] => 0.999
    [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=77237&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=77237&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=77237&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=77237&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=77237&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=77237&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=77237&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=77237&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=77237&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=77237&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=77237&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=77237&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=77237&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=77237&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77237&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=77237&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=77237&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=77237&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77237&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=77237&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=77237&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#218261) next »