Skip to content

Wildly wrong DateTime::diff() result on php 7.2.12 (and newer) and php 7.3.0 RC4 (and newer) #51

@wyattoday

Description

@wyattoday

We don't use this library directly, however the current version merged in php has a number of bugs related to timediff.

$utc_tz = new DateTimeZone('UTC');
$curr_time = DateTime::createFromFormat('Y-m-d H:i:s.u', '2018-11-22 13:27:52.089635', $utc_tz);
$customer_time = DateTime::createFromFormat('Y-m-d H:i:s', '2018-11-22 13:27:52', $utc_tz);

print_r($curr_time->diff($customer_time, true));

print_r($curr_time->diff($customer_time, false));

There's less than a second between those 2 times, and yet result from both print_r() statements (with the "absolute" comparison on/off) is:

DateInterval Object
(
    [y] => -1
    [m] => 11
    [d] => 30
    [h] => 23
    [i] => 59
    [s] => 59
    [f] => 0.910365
    [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
)

This is beyond wrong. The older timelib also gave a wrong result for the microseconds, but at least it wasn't "out of this universe" wrong:

DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 0
    [f] => -0.089635
    [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
)

Same result for either "absolute" parameter true/false. ("f" should be positive when absolute is true).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions