Bug #75992 [Opn->Nab]: DateTime::createFromFormat() does not work with years > 4 digits

From: Date: Thu, 22 Feb 2018 11:12:00 +0000
Subject: Bug #75992 [Opn->Nab]: DateTime::createFromFormat() does not work with years > 4 digits
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214065@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75992&edit=1 ID: 75992 Updated by: pmmaga@php.net Reported by: dktapps at pmmp dot io -Summary: DateTime::createFromString() does not work with years > 4 digits +Summary: DateTime::createFromFormat() does not work with years > 4 digits -Status: Open +Status: Not a bug Type: Bug Package: Date/time related Operating System: Windows 10 PHP Version: 7.2.2 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php The docs for DateTime::createFromFormat() clearly state: > Y A full numeric representation of a year, 4 digits The fact that this works as you expect for output doesn't imply that it should work for input. Previous Comments: ------------------------------------------------------------------------ [2018-02-22 10:23:49] dktapps at pmmp dot io Description: ------------ DateTime formats can be created using format() which have >4 digits in the year, which cannot be parsed using createFromFormat() with the same format-string. As seen below the same format is used both times. This bug report looks absurd, but I've had similar issues been auto-reported to my crash archive when users put absurd values in configuration, and this appears to be why. Test script: --------------- <?php $datetime = new \DateTime('@' . PHP_INT_MAX); $str = $datetime->format("Y-m-d H:i:s O"); var_dump($str); //275808-11-04 10:06:43 +0000 var_dump(\DateTime::createFromFormat("Y-m-d H:i:s O", $str)); //bool(false) ?> Expected result: ---------------- Either: bool(false) bool(false) OR string(33) "292277026596-12-04 15:30:07 +0000 object(DateTime)#2 (3) { ["date"]=> string(34) "292277026596-12-04 15:30:07.000000 ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } Actual result: -------------- string(33) "292277026596-12-04 15:30:07 +0000" bool(false) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75992&edit=1

« previous php.bugs (#214065) next »