Edit report at https://bugs.php.net/bug.php?id=69205&edit=1
ID: 69205
Comment by: nd dot wortel at gmail dot com
Reported by: nd dot wortel at gmail dot com
Summary: DateTime for December 31st fails once every 400
years
Status: Assigned
Type: Bug
Package: Date/time related
Operating System: Ubuntu 14.04
PHP Version: 5.5.22
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
The following test shows that this is a problem in PHP 5.4, 5.5, 5.6 and 7. PHP 5.3 does not seem to
be affected: https://travis-ci.org/nicwortel/nicwortel/php-date-bug
Previous Comments:
------------------------------------------------------------------------
[2015-06-15 11:35:14] riggsfolly at gmail dot com
This also appears to be a problem in all releases
Errored in 5.3/5.4/5.5/5.6
------------------------------------------------------------------------
[2015-06-15 11:31:14] riggsfolly at gmail dot com
This also appears to be demonstrating the same or similiar problem
<?php
$test = date_create("-1000-12-27");
echo date_format($test, 'Y-m-d H:i:s').PHP_EOL;
date_modify($test, '+1 day');
echo date_format($test, 'Y-m-d H:i:s').PHP_EOL.PHP_EOL;
$test = date_create("-2000-12-27");
echo date_format($test, 'Y-m-d H:i:s').PHP_EOL;
date_modify($test, '+1 day');
echo date_format($test, 'Y-m-d H:i:s').PHP_EOL.PHP_EOL;
$test = date_create("-3000-12-27");
echo date_format($test, 'Y-m-d H:i:s').PHP_EOL;
date_modify($test, '+1 day');
echo date_format($test, 'Y-m-d H:i:s').PHP_EOL.PHP_EOL;
RESULTS:
-1000-12-28 00:00:00
-1000-12-30 00:00:00
-2000-12-27 00:00:00
-2000-12-28 00:00:00
-3000-12-28 00:00:00
-3000-12-30 00:00:00
------------------------------------------------------------------------
[2015-03-09 15:23:40] nd dot wortel at gmail dot com
Description:
------------
A DateTime (or DateTimeImmutable) object can not be created with date '2369-12-31',
'2769-12-31', '3169-12-31', etc. Instead, a DateTime object with date
'2370-01-00' (or '2770-01-00', '3170-01-00', etc.) is created. This
happens every 400 years on December 31st.
Years in the past are not affected: '1969-12-31' and '1569-12-31' work just
fine. Therefore, this has probably something to do with the Unix time system.
Note: my PHP version is actually PHP 5.5.9-1ubuntu4.6.
This bug is probably also causing the behavior described here: https://bugs.php.net/bug.php?id=67993
Test script:
---------------
<?php
$dateTime = new DateTime('2369-12-31'); // or 2769, 3169, etc.
var_dump($dateTime);
Expected result:
----------------
object(DateTime)[1]
public 'date' => string '2369-12-31 00:00:00' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Amsterdam' (length=16)
Actual result:
--------------
object(DateTime)[1]
public 'date' => string '2370-01-00 00:00:00' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Amsterdam' (length=16)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69205&edit=1