Bug #66836 [Ver]: DateTime::createFromFormat 'U' with pre 1970 dates fails parsing
| From: | cmb@php.net | Date: | Mon, 11 Jul 2016 13:49:38 +0000 |
| Subject: | Bug #66836 [Ver]: DateTime::createFromFormat 'U' with pre 1970 dates fails parsing | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-202200@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66836&edit=1
ID: 66836
Updated by: cmb@php.net
Reported by: rami dot alnawas at gmail dot com
Summary: DateTime::createFromFormat 'U' with pre 1970 dates
fails parsing
Status: Verified
Type: Bug
Package: Date/time related
Operating System: Ubuntu
PHP Version: Irrelevant
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
The test fails because of the date.timezone warning. So everything
is okay. Sorry for the noise.
Previous Comments:
------------------------------------------------------------------------
[2016-07-11 13:49:23] derick@php.net
@cmb, I can't reproduce that:
[GIT: PHP-5.6][PHP: 5.6.20-dev ]
derick@whisky:~/dev/php/php-src.git $ php
<?php
$timestamp = '-1';
$dt = DateTime::createFromFormat('U', $timestamp);
var_dump($dt, $dt->format('U'), $timestamp);
?>
But fixed in .25-dev:
[GIT: PHP-5.6][PHP: 5.6.25-dev ]
derick@whisky:~/dev/php/php-src.git $ php
<?php
$timestamp = '-1';
$dt = DateTime::createFromFormat('U', $timestamp);
var_dump($dt, $dt->format('U'), $timestamp);
?>
-:4:
class DateTime#1 (3) {
public $date =>
string(26) "1969-12-31 23:59:59.000000"
public $timezone_type =>
int(1)
public $timezone =>
string(6) "+00:00"
}
-:4:
string(2) "-1"
-:4:
string(2) "-1"
------------------------------------------------------------------------
[2016-07-11 13:11:54] cmb@php.net
Related To: Bug #66836
------------------------------------------------------------------------
[2016-07-11 13:11:53] cmb@php.net
I can confirm that the issue is solved in PHP-7.0 and master, but
not in PHP-5.6, as the following PHPT fails there:
--TEST--
Bug #66836 (DateTime::createFromFormat 'U' with pre 1970 dates fails parsing)
--FILE--
<?php
$timestamp = '-1';
$dt = DateTime::createFromFormat('U', $timestamp);
var_dump($dt->format('U') === $timestamp);
?>
--EXPECT--
bool(true)
------------------------------------------------------------------------
[2016-07-11 12:52:38] derick@php.net
I've pushed it to 5.6 and up - there is no need for a further back port.
------------------------------------------------------------------------
[2016-07-11 12:35:05] cmb@php.net
I can confirm the issue, see <https://3v4l.org/mT3CX>.
However, it
has recently been fixed in master[1], and might be backported.
[1] <https://github.com/php/php-src/commit/822ca45220db0b864af9dc79b94bda03a9323621>
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=66836
--
Edit this bug report at https://bugs.php.net/bug.php?id=66836&edit=1