Bug #55686 [Com]: DateTime object getting stuck on Feb 29th
| From: | john at gbd dot co dot uk | Date: | Mon, 20 Feb 2012 21:51:22 +0000 |
| Subject: | Bug #55686 [Com]: DateTime object getting stuck on Feb 29th | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-167666@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55686&edit=1
ID: 55686
Comment by: john at gbd dot co dot uk
Reported by: salathe@php.net
Summary: DateTime object getting stuck on Feb 29th
Status: Assigned
Type: Bug
Package: Date/time related
PHP Version: trunk-SVN-2011-09-13 (SVN)
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
Is this important?
Pre-Julian dates were different, Feb had 23 or 24 days rather than the current
28/29 days, so any date pre 45BC is a bit academic. and probably beyond the scope
of a PHP date function. http://en.wikipedia.org/wiki/Julian_calendar
Previous Comments:
------------------------------------------------------------------------
[2011-09-13 20:52:21] salathe@php.net
Description:
------------
Some dates falling on February 29th in negative years can not have an interval of
one day added to them.
The pattern appears to be years of the form -n16, but some years behave as
expected (e.g. -816 and -416 in the test script below).
Test script:
---------------
<?php
for ($i = -1000; $i < 1000; $i++) {
$date = new DateTime('midnight', new DateTimeZone('UTC'));
$date->setDate($i, 2, 29);
// Rolled over into March, no Feb 29th, skip
if ($date->format('M') !== 'Feb') {
continue;
}
$next = clone $date;
$next->add(new DateInterval('P1D'));
if ($date->format('Y-m-d') === $next->format('Y-m-d')) {
echo $next->format('Y-m-d l') . PHP_EOL;
}
}
?>
Expected result:
----------------
No output is expected.
Actual result:
--------------
-0916-02-29 Friday
-0716-02-29 Tuesday
-0616-02-29 Sunday
-0516-02-29 Friday
-0316-02-29 Tuesday
-0216-02-29 Sunday
-0116-02-29 Friday
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55686&edit=1