Bug #69211 [Opn]: DateTime Diff is off by 3
| From: | lr at cwd dot at | Date: | Tue, 10 Mar 2015 12:43:21 +0000 |
| Subject: | Bug #69211 [Opn]: DateTime Diff is off by 3 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-191283@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69211&edit=1
ID: 69211
User updated by: lr at cwd dot at
Reported by: lr at cwd dot at
-Summary: DateTime Diff is off by 2
+Summary: DateTime Diff is off by 3
Status: Open
Type: Bug
Package: Date/time related
Operating System: Linux
PHP Version: 5.4.38
Block user comment: N
Private report: N
New Comment:
summary fix
Previous Comments:
------------------------------------------------------------------------
[2015-03-10 12:40:51] lr at cwd dot at
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 this bug report at https://bugs.php.net/bug.php?id=69211&edit=1