Bug #73086 [NEW]: createFromFormat method wrongly parses rfc2616 date
| From: | simon at programujem dot eu | Date: | Thu, 15 Sep 2016 07:45:27 +0000 |
| Subject: | Bug #73086 [NEW]: createFromFormat method wrongly parses rfc2616 date | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-204053@lists.php.net to get a copy of this message | ||
From: simon at programujem dot eu
Operating system: Windows
PHP version: 7.0.10
Package: Date/time related
Bug Type: Bug
Bug description:createFromFormat method wrongly parses rfc2616 date
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 bug report at https://bugs.php.net/bug.php?id=73086&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73086&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73086&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73086&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73086&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73086&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73086&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73086&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73086&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73086&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73086&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73086&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73086&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73086&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73086&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73086&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73086&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73086&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73086&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73086&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73086&r=mysqlcfg