php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77235 DateTime::diff Wrong result if subsecond difference
Submitted: 2018-12-04 06:23 UTC Modified: 2018-12-04 09:50 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: arkham dot vm at gmail dot com Assigned:
Status: Duplicate Package: Date/time related
PHP Version: 7.2.12 OS: CentOs 7.5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: arkham dot vm at gmail dot com
New email:
PHP Version: OS:

 

 [2018-12-04 06:23 UTC] arkham dot vm at gmail dot com
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
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-04 06:30 UTC] arkham dot vm at gmail dot com
-Package: *General Issues +Package: Date/time related
 [2018-12-04 06:30 UTC] arkham dot vm at gmail dot com
Change package to "Date/time related"
 [2018-12-04 09:50 UTC] derick@php.net
-Status: Open +Status: Duplicate
 [2018-12-04 09:50 UTC] derick@php.net
Duplicate of #77097, which is already fixed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC