php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77237 DateTime diff wrong when using milliseconds
Submitted: 2018-12-04 08:43 UTC Modified: 2018-12-04 10:01 UTC
From: bstanescu at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: Date/time related
PHP Version: 7.2.12 OS: Ubuntu 16.0.4
Private report: No CVE-ID: None
 [2018-12-04 08:43 UTC] bstanescu at gmail dot com
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
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-04 08:50 UTC] bstanescu at gmail dot com
Edit: 

Expected fraction is 
    [f] => -0.001
Not 
    [f] => -0.123
 [2018-12-04 10:01 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2018-12-04 10:01 UTC] cmb@php.net
Duplicate of bug #77097.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 03:01:29 2024 UTC