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: -
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: Open Package: Date/time related
PHP Version: 7.2.2RC1 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Nov 28 08:01:23 2020 UTC