php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74524 Date diff is bad calculated, in same time zone
Submitted: 2017-05-01 20:59 UTC Modified: 2017-05-06 19:02 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: kalita dot michal at gmail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 7.1.4 OS: Linux
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-05-01 20:59 UTC] kalita dot michal at gmail dot com
Description:
------------
Calculated diff is 7 months, 14 days and -1 hour.

It doen't make sense, why it is not 7 months, 13 days and 23 hours.

This bug is in versions 5.4.45, 5.6.30, 7 and newest. (https://3v4l.org/6OOuG)


Test script:
---------------
$a = new DateTime("2017-11-17 22:05:26.000000");
$b = new DateTime("2017-04-03 22:29:15.079459");

$diff = $a->diff($b);

return $diff->h;

Expected result:
----------------
23

Actual result:
--------------
-1

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-02 12:22 UTC] andrew dot nester dot dev at gmail dot com
thanks for reporting the issue!
I've been trying to reproduce it on latest PHP7.1 version (7.1.6-dev) and seems it's fixed already.
Anyway, I've added test to check that it works (see my PR)
 [2017-05-02 12:33 UTC] derick@php.net
Andrew, it might look fixed for you because you have a different timezone with different DST rules configured.
 [2017-05-02 20:06 UTC] andrew dot nester dot dev at gmail dot com
Thanks Derick!
gonna rework my pull request
 [2017-05-03 07:18 UTC] andrew dot nester dot dev at gmail dot com
Just added reworked pull request to this issue. Here is the link https://github.com/php/php-src/pull/2506
 [2017-05-06 19:02 UTC] heiglandreas@php.net
This is a DST issue as can be seen in https://3v4l.org/9AWOI

The default Timezone of 3v4l.org is Europe/Amsterdam which has DST and therefore has the issue!
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC