Bug #70126 [NEW]: Wrong calculation of the difference between two dates
| From: | php at tul dot io | Date: | Fri, 24 Jul 2015 09:50:38 +0000 |
| Subject: | Bug #70126 [NEW]: Wrong calculation of the difference between two dates | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-194669@lists.php.net to get a copy of this message | ||
From: php at tul dot io
Operating system: any
PHP version: 7.0.0beta2
Package: Date/time related
Bug Type: Bug
Bug description:Wrong calculation of the difference between two dates
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 bug report at https://bugs.php.net/bug.php?id=70126&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70126&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70126&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70126&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70126&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70126&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70126&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70126&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70126&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70126&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70126&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70126&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70126&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70126&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70126&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70126&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70126&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70126&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70126&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70126&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70126&r=mysqlcfg