Bug #78496 [Com]: date_create rolls a day back on year 0000 timestamp

From: Date: Thu, 05 Sep 2019 23:41:52 +0000
Subject: Bug #78496 [Com]: date_create rolls a day back on year 0000 timestamp
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222582@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78496&edit=1 ID: 78496 Comment by: alexanderpas at gmail dot com Reported by: dzuczek at dlc-solutions dot com Summary: date_create rolls a day back on year 0000 timestamp Status: Open Type: Bug Package: Date/time related Operating System: Linux PHP Version: 7.2.22 Block user comment: N Private report: N New Comment: ISO 8601 defines the year zero as the year 1 BC in the Gregorian calendar. The last few days in January are also affected. Previous Comments: ------------------------------------------------------------------------ [2019-09-05 22:12:03] requinix@php.net Related To: Bug #78499 ------------------------------------------------------------------------ [2019-09-05 16:47:38] cmb@php.net Well, actually there is no year 0 in the Gregorian calendar. ------------------------------------------------------------------------ [2019-09-05 16:24:27] dzuczek at dlc-solutions dot com More tests, looks like it's just February dates... 0000-01-20 00:00:00 UTC (works) https://3v4l.org/2hPTv 0000-02-20 00:00:00 UTC (fails) https://3v4l.org/manbk 0000-03-20 00:00:00 UTC (works) https://3v4l.org/SMI46 ------------------------------------------------------------------------ [2019-09-05 16:02:08] dzuczek at dlc-solutions dot co Passing a date instead of seconds does work: https://3v4l.org/cRcKS <?php $date_time = date_create('0000-02-20 00:00:00 UTC'); print_r($date_time); $date_time = date_create('0001-02-20 00:00:00 UTC'); print_r($date_time); ?> ------------------------------------------------------------------------ [2019-09-05 15:56:23] dzuczek at dlc-solutions dot com Description: ------------ date_create seems to roll back a day when given a timestamp in the year 0000 this worked as expected in PHP 7.1, does not work in PHP 7.2 or greater Test script: --------------- Not working (year 0000): https://3v4l.org/manbk Working (year 0001): https://3v4l.org/uMjtB <?php $timestamp = strtotime('0000-02-20 00:00:00 UTC'); // has issues $timestamp2 = strtotime('0001-02-20 00:00:00 UTC'); // this is okay // this has issues print $timestamp . "\n"; $date_time = date_create('@' . $timestamp); print_r($date_time); // this is fine print $timestamp2 . "\n"; $date_time2 = date_create('@' . $timestamp2); print_r($date_time2); ?> Expected result: ---------------- Using 0000-02-20 00:00:00 UTC Expected (PHP 7.1) DateTime Object ( [date] => 0000-02-20 00:00:00.000000 [timezone_type] => 1 [timezone] => +00:00 ) Actual result: -------------- Using 0000-02-20 00:00:00 UTC Actual (PHP 7.2+) DateTime Object ( [date] => 0000-02-19 00:00:00.000000 [timezone_type] => 1 [timezone] => +00:00 ) The resulting date has been rolled back a day. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78496&edit=1

« previous php.bugs (#222582) next »