Bug #70126 [Opn->Sus]: Wrong calculation of the difference between two dates
| From: | derick@php.net | Date: | Fri, 24 Jul 2015 10:33:20 +0000 |
| Subject: | Bug #70126 [Opn->Sus]: Wrong calculation of the difference between two dates | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-194670@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70126&edit=1
ID: 70126
Updated by: derick@php.net
Reported by: php at tul dot io
Summary: Wrong calculation of the difference between two
dates
-Status: Open
+Status: Suspended
Type: Bug
Package: Date/time related
Operating System: any
PHP Version: 7.0.0beta2
-Assigned To:
+Assigned To: derick
Block user comment: N
Private report: N
New Comment:
timelib development lives at http://github.com/derickr/timelib - the one in PHP is a
bundled version. Timelib does right now not have a test harnass for diffs, although there is a
tester for it: https://github.com/derickr/timelib/blob/master/tests/tester-diff.c
Once it's fixed (and tested) in timelib, I'm happy to resync it back to PHP.
Previous Comments:
------------------------------------------------------------------------
[2015-07-24 09:50:38] php at tul dot io
Description:
------------
DateTime::diff() reports the wrong number of days and months when not in an inverted order (start
date < end date). To reproduce, the two dates used as input have to be even number of months
apart and the day of the start date has to be greater than the day of the end date (e.g. 2015-01-31
to 2015-03-01).
Test script:
---------------
<?php
$date1 = new DateTime('2015/01/31');
$date2 = new DateTime('2015/03/01');
print_r($date1->diff($date2));
print_r($date2->diff($date1));
Expected result:
----------------
DateInterval Object
(
[y] => 0
[m] => 1
[d] => 1
[h] => 0
[i] => 0
[s] => 0
[weekday] => 0
[weekday_behavior] => 0
[first_last_day_of] => 0
[invert] => 0
[days] => 29
[special_type] => 0
[special_amount] => 0
[have_weekday_relative] => 0
[have_special_relative] => 0
)
DateInterval Object
(
[y] => 0
[m] => 1
[d] => 1
[h] => 0
[i] => 0
[s] => 0
[weekday] => 0
[weekday_behavior] => 0
[first_last_day_of] => 0
[invert] => 1
[days] => 29
[special_type] => 0
[special_amount] => 0
[have_weekday_relative] => 0
[have_special_relative] => 0
)
Actual result:
--------------
DateInterval Object
(
[y] => 0
[m] => 0
[d] => 29
[h] => 0
[i] => 0
[s] => 0
[weekday] => 0
[weekday_behavior] => 0
[first_last_day_of] => 0
[invert] => 0
[days] => 29
[special_type] => 0
[special_amount] => 0
[have_weekday_relative] => 0
[have_special_relative] => 0
)
DateInterval Object
(
[y] => 0
[m] => 1
[d] => 1
[h] => 0
[i] => 0
[s] => 0
[weekday] => 0
[weekday_behavior] => 0
[first_last_day_of] => 0
[invert] => 1
[days] => 29
[special_type] => 0
[special_amount] => 0
[have_weekday_relative] => 0
[have_special_relative] => 0
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70126&edit=1