Bug #71687 [NEW]: Adding one year to a leap day produces incorrect date
| From: | kungfutse at hotmail dot com | Date: | Mon, 29 Feb 2016 10:41:37 +0000 |
| Subject: | Bug #71687 [NEW]: Adding one year to a leap day produces incorrect date | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-199521@lists.php.net to get a copy of this message | ||
From: kungfutse at hotmail dot com
Operating system: Linux
PHP version: 5.6.18
Package: Date/time related
Bug Type: Bug
Bug description:Adding one year to a leap day produces incorrect date
Description:
------------
When adding one year (new DateInterval('P1Y')) to a leap day (new
DateTime('2016-02-29')) results in incorrect date. It should return
2017-02-28 but returns 2017-03-01 instead.
For comparison, MariaDB 10 returns the correct date when doing SELECT
DATE_ADD(DATE('2016-02-29'), INTERVAL 1 YEAR);
Test script:
---------------
var_dump( (new \DateTime('2016-02-29'))->add(new \DateInterval('P1Y'))
);
Expected result:
----------------
object(DateTime)#1 (3) {
["date"]=>
string(26) "2017-02-28 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(15) "Europe/Helsinki"
}
Actual result:
--------------
object(DateTime)#1 (3) {
["date"]=>
string(26) "2017-03-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(15) "Europe/Helsinki"
}
--
Edit bug report at https://bugs.php.net/bug.php?id=71687&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71687&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71687&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71687&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71687&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71687&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71687&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71687&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71687&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71687&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71687&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71687&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71687&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71687&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71687&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71687&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71687&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71687&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71687&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71687&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71687&r=mysqlcfg