Bug #69211 [NEW]: DateTime Diff is off by 2
| From: | lr at cwd dot at | Date: | Tue, 10 Mar 2015 12:40:54 +0000 |
| Subject: | Bug #69211 [NEW]: DateTime Diff is off by 2 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-191282@lists.php.net to get a copy of this message | ||
From: lr at cwd dot at
Operating system: Linux
PHP version: 5.4.38
Package: Date/time related
Bug Type: Bug
Bug description:DateTime Diff is off by 2
Description:
------------
DateTime::diff() ist off by 3 days when year roll over
Test script:
---------------
<?php
date_default_timezone_set('UTC');
$datetime1 = new DateTime('2015-01-01');
$datetime2 = new DateTime('2015-03-10');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%y years %m months and %d days')."\n";
$datetime1 = new DateTime('2014-12-31');
$datetime2 = new DateTime('2015-03-10');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%y years %m months and %d days')."\n";
$datetime1 = new DateTime('1951-12-31');
$datetime2 = new DateTime('2015-03-10');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%y years %m months and %d days')."\n";
Expected result:
----------------
0 years 2 months and 9 days
0 years 2 months and 10 days
63 years 2 months and 10 days
Actual result:
--------------
0 years 2 months and 9 days
0 years 2 months and 7 days
63 years 2 months and 7 days
--
Edit bug report at https://bugs.php.net/bug.php?id=69211&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69211&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69211&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69211&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69211&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69211&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69211&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69211&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69211&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69211&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69211&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69211&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69211&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69211&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69211&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69211&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69211&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69211&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69211&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69211&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69211&r=mysqlcfg