php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75855 DateTime::diff class does not take into account microseconds in some cases
Submitted: 2018-01-21 19:33 UTC Modified: 2021-04-06 18:23 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: marcospassos dot com at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 7.2.2RC1 OS:
Private report: No CVE-ID: None
 [2018-01-21 19:33 UTC] marcospassos dot com at gmail dot com
Description:
------------
The method DateTime::diff() of the native DateTime class does not take into account microseconds, as explained below.

Start: 2015-08-31 00:00:00.000001
End: 2015-09-01 00:00:00.000000

The diff object returned by the method DateTime::diff() for these dates reports that a whole day has been elapsed since the start date. As evidenced, such result is wrong since 1 microsecond is missing in the interval to complete a full day.

In an addition, the result of the number of microseconds is expected to be positive, as all the units do. However, in this case, the result is negative.

Test script:
---------------
https://3v4l.org/6INks

Expected result:
----------------
Years: 0
Days: 0
Total days: 0
Months: 0
Hours: 0
Minutes: 0
Seconds: 0
Microseconds: 1.0E-6

Actual result:
--------------
Years: 0
Days: 1
Total days: 1
Months: 0
Hours: 0
Minutes: 0
Seconds: 0
Microseconds: 1.0E-6

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-06 18:23 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2021-04-06 18:23 UTC] derick@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP --
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.

Looks from the 3v4l link that that got fixed in 7.2.12 already.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Apr 10 14:01:24 2021 UTC