Bug #53879 [Opn]: DateTime::createFromFormat() fails to parse cookie expiration date

From: Date: Wed, 27 Nov 2013 17:44:02 +0000
Subject: Bug #53879 [Opn]: DateTime::createFromFormat() fails to parse cookie expiration date
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182971@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=53879&edit=1 ID: 53879 Updated by: derick@php.net Reported by: noels01 at gmx dot net Summary: DateTime::createFromFormat() fails to parse cookie expiration date Status: Open Type: Bug Package: Date/time related Operating System: Win 7 PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: The original cookie spec uses RFC 850, which has the year with only two digits. So this is technically not a bug - however - it's not really nice either. The l vs D point is moot, as the createFromFormat treats them as the same. However, I think we should change the COOKIE format to what http://en.wikipedia.org/wiki/HTTP_cookie#Expires_and_Max-Age and RFC 1036 say: "Tue, 15 Jan 2013 21:47:38 GMT" or as format specifiers: "l, d M Y H:i:s T" (ie, swap y for Y, and remove the -'s between d, M and Y). Previous Comments: ------------------------------------------------------------------------ [2012-09-29 17:33:00] bwhitehead at tableausoftware dot com Confirmed on MacOS 10.7.4 (PHP 5.3.10) According to this page: http://php.net/manual/en/class.datetime.php: const string COOKIE = "l, d-M-y H:i:s T" ; According to this page: http://php.net/manual/en/datetime.createfromformat.php Value should be:"D, d-M-Y H:i:s T" or "D, d-M-Y H:i:s e" The leading "Day of Week" (l) and "Year" (y) formats are incorrect. Confirmed parsing of standard cookie date with either of the above formats. Code: DateTime::createFromFormat("D, d-M-Y H:i:s T", "Mon, 29-Sep-2014 01:21:00 GMT"); DateTime::createFromFormat("D, d-M-Y H:i:s e", "Mon, 29-Sep-2014 01:21:00 GMT"); Result: object(DateTime)#1 (3) { ["date"]=> string(19) "2014-09-29 01:21:00" ["timezone_type"]=> int(2) ["timezone"]=> string(3) "GMT" } array(4) { ["warning_count"]=> int(0) ["warnings"]=> array(0) { } ["error_count"]=> int(0) ["errors"]=> array(0) { } } ------------------------------------------------------------------------ [2011-01-29 16:43:13] noels01 at gmx dot net Description: ------------ The class DateTime is supposed to handle date strings like used for cookie expiration dates. It explicitly defines the format DateTime::COOKIE but fails to parse it. Test script: --------------- <?php $date = DateTime::createFromFormat(DateTime::COOKIE, "Mon, 21-Jan-2041 15:24:52 GMT"); print_r($date); ?> Same goes for <?php $date = date_parse_from_format(DateTime::COOKIE, "Mon, 21-Jan-2041 15:24:52 GMT"); print_r($date); ?> Expected result: ---------------- Something with a date instead of NULL O.o Actual result: -------------- Array ( [year] => 2020 [month] => 1 [day] => 21 [hour] => 41 [minute] => 15 [second] => 24 [fraction] => [warning_count] => 1 [warnings] => Array ( [25] => The parsed time was invalid ) [error_count] => 4 [errors] => Array ( [16] => Unexpected data found. [22] => The timezone could not be found in the database [25] => Trailing data ) [is_localtime] => 1 [zone_type] => 0 ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=53879&edit=1

« previous php.bugs (#182971) next »