|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-11-23 06:20 UTC] mjpelmear at gmail dot com
[2013-11-23 16:46 UTC] salathe@php.net
[2013-11-24 03:43 UTC] mjpelmear at gmail dot com
[2013-11-24 18:27 UTC] derick@php.net
-Status: Open
+Status: Not a bug
[2013-11-24 18:27 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 14 18:00:02 2025 UTC |
Description: ------------ date_create_from_format() improperly parses dates in "!ndY" format, but reports the problem as being with the data, not with the parser's [lack of] support for the format. This date format is a strange one, but we encountered it in data files received from a client, so it seems to be in use, albeit undesirable. Analysis: --------- The root issue is that the parser is reading the incoming string from left to right, but when doing so it has no way to determine whether the month is one or two digits (since "n" means the month would be a single digit if < 10). See timelib_parse_from_format() in ext/date/lib/parse_date.c. Note that while it would be impossible to support a format like "!njY" because this would have some ambiguous cases ("1112013" for example), it is at least possible to support "!ndY" and similar cases. Test script: --------------- $date = date_create_from_format( '!ndY', '3071989' ); assert( $date->format('Y-m-d') == '1989-03-07' ); // assertion fails. print_r(DateTime::getLastErrors()); echo PHP_EOL; print_r($date); echo PHP_EOL; Expected result: ---------------- The assertion should succeed, or we should receive a meaningful error message indicating that this date format isn't supported. Actual result: -------------- The assertion fails (DateTime shows the date as "0991-08-10", in Y-m-d format). DateTime::getLastErrors() simply indicates that the parsed date was invalid ("The parsed date was invalid").