Bug #64040 [Com]: DateTime::createFromFormat() incorrectly parses illogical dates

From: Date: Fri, 25 Apr 2014 07:16:26 +0000
Subject: Bug #64040 [Com]: DateTime::createFromFormat() incorrectly parses illogical dates
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185430@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64040&edit=1 ID: 64040 Comment by: metamarkers at gmail dot com Reported by: tagadvance at gmail dot com Summary: DateTime::createFromFormat() incorrectly parses illogical dates Status: Open Type: Bug Package: Date/time related Operating System: Linux PHP Version: Irrelevant Block user comment: N Private report: N New Comment: "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" There is no amount of code that can be written to error-correct the programmer. Previous Comments: ------------------------------------------------------------------------ [2013-01-21 20:21:32] tagadvance at gmail dot com Description: ------------ --- From manual page: http://www.php.net/datetime.createfromformat --- The DateTime::createFromFormat() method incorrectly parses an illogical date. I have tested this on version 5.3.3 (CentOS) and 5.4.6 (Ubuntu). Test script: --------------- <?php // November 16 falls on a Friday, NOT a Wednesday $date = 'Wednesday 16 November 2012'; $format = 'l d M Y'; try { $dateTime = DateTime::createFromFormat($format, $date); $formattedDateTime = $dateTime->format($format); echo $formattedDateTime . PHP_EOL; // prints "Wednesday 21 Nov 2012" } catch (Exception $e) { // no exception is thrown =( echo $e->getMessage(); } ?> Expected result: ---------------- I expect the createFromFormat method to throw an error if the date is illogical. At the very least a warning should be added to the log. Actual result: -------------- The createFromFormat parses the illogical date. The day seems to take precedence over the date. I am just guessing here, but it then seems to round up by one week so that the date makes sense. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64040&edit=1

« previous php.bugs (#185430) next »