Bug #66156 [NEW]: date_create_from_format() fails for "!ndY" format
| From: | mjpelmear at gmail dot com | Date: | Sat, 23 Nov 2013 06:15:17 +0000 |
| Subject: | Bug #66156 [NEW]: date_create_from_format() fails for "!ndY" format | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-182899@lists.php.net to get a copy of this message | ||
From: mjpelmear at gmail dot com
Operating system: Any
PHP version: master-Git-2013-11-23 (Git)
Package: Date/time related
Bug Type: Bug
Bug description:date_create_from_format() fails for "!ndY" format
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").
--
Edit bug report at https://bugs.php.net/bug.php?id=66156&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66156&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66156&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66156&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66156&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66156&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66156&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66156&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66156&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66156&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66156&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66156&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66156&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66156&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66156&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66156&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66156&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66156&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66156&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66156&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66156&r=mysqlcfg