Bug #73086 [Opn]: createFromFormat method wrongly parses rfc2616 date
| From: | cmb@php.net | Date: | Thu, 15 Sep 2016 10:27:34 +0000 |
| Subject: | Bug #73086 [Opn]: createFromFormat method wrongly parses rfc2616 date | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-204057@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73086&edit=1
ID: 73086
Updated by: cmb@php.net
Reported by: simon at programujem dot eu
Summary: createFromFormat method wrongly parses rfc2616 date
Status: Open
Type: Bug
Package: Date/time related
Operating System: Windows
PHP Version: 7.0.10
Block user comment: N
Private report: N
New Comment:
There is no 'Thu, 4 Sep 2016 07:12:28 GMT', so I see three
possible solutions:
1. fail
2. ignore the weekday
3. ignore the day
Obviously, the date parser chooses option (3). In my opinion, that
is fine, because it's more liberal than (1), but probably it would
be good to emit a notice or warning in this case.
Previous Comments:
------------------------------------------------------------------------
[2016-09-15 07:45:20] simon at programujem dot eu
Description:
------------
The method createFromFormat of both classes \DateTime and \DateTimeImmutable incorrectly parses
rfc2616 formatted date used in, but not limited to, Last-Modified and If-Modified-Since headers as
defined by w3.
Using the following format: 'D, d M Y H:i:s e' it does actually parse the passed rfc2616
string but the days do not match for some dates, eg. trying to parse the date 'Thu, 4 Sep 2016
07:12:28 GMT' will result in \DateTime instance or \DateTimeImmutable respectively of not the
fourth September but 8th instead.
The targeted PHP version is 7.0.10 running on Windows 7 x64, but the problem has been noticed in PHP
5.6.25 (running on a Linux distribution) as well.
Test script:
---------------
<?php
$format = 'D, d M Y H:i:s e';
$output = (\DateTimeImmutable::createFromFormat($format, 'Thu, 1 Sep 2016 07:12:28
GMT'))->format(\DateTime::ATOM);
print_r($output.'<br>'); // 2016-09-01T07:12:28+00:00
$output = (\DateTimeImmutable::createFromFormat($format, 'Thu, 2 Sep 2016 07:12:28
GMT'))->format(\DateTime::ATOM);
print_r($output.'<br>'); // 2016-09-08T07:12:28+00:00
$output = (\DateTimeImmutable::createFromFormat($format, 'Thu, 3 Sep 2016 07:12:28
GMT'))->format(\DateTime::ATOM);
print_r($output.'<br>'); // 2016-09-08T07:12:28+00:00
$output = (\DateTimeImmutable::createFromFormat($format, 'Thu, 4 Sep 2016 07:12:28
GMT'))->format(\DateTime::ATOM);
print_r($output.'<br>'); // 2016-09-08T07:12:28+00:00
$output = (\DateTimeImmutable::createFromFormat($format, 'Thu, 12 Sep 2016 07:12:28
GMT'))->format(\DateTime::ATOM);
print_r($output.'<br>'); // 2016-09-15T07:12:28+00:00
$output = (\DateTimeImmutable::createFromFormat($format, 'Thu, 13 Sep 2016 07:12:28
GMT'))->format(\DateTime::ATOM);
print_r($output.'<br>'); // 2016-09-15T07:12:28+00:00
$output = (\DateTimeImmutable::createFromFormat($format, 'Thu, 14 Sep 2016 07:12:28
GMT'))->format(\DateTime::ATOM);
print_r($output.'<br>'); // 2016-09-15T07:12:28+00:00
$output = (\DateTimeImmutable::createFromFormat($format, 'Thu, 15 Sep 2016 07:12:28
GMT'))->format(\DateTime::ATOM);
print_r($output.'<br>'); // 2016-09-15T07:12:28+00:00
Expected result:
----------------
2016-09-01T07:12:28+00:00
2016-09-02T07:12:28+00:00
2016-09-03T07:12:28+00:00
2016-09-04T07:12:28+00:00
2016-09-12T07:12:28+00:00
2016-09-13T07:12:28+00:00
2016-09-14T07:12:28+00:00
2016-09-15T07:12:28+00:00
Actual result:
--------------
2016-09-01T07:12:28+00:00
2016-09-08T07:12:28+00:00
2016-09-08T07:12:28+00:00
2016-09-08T07:12:28+00:00
2016-09-15T07:12:28+00:00
2016-09-15T07:12:28+00:00
2016-09-15T07:12:28+00:00
2016-09-15T07:12:28+00:00
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73086&edit=1