Edit report at https://bugs.php.net/bug.php?id=75577&edit=1
ID: 75577
Comment by: rob dot bast at gmail dot com
Reported by: php-bugs at dennis dot birkholz dot biz
Summary: DateTime::createFromFormat does not accept
RFC3339_EXTENDED format
Status: Assigned
Type: Bug
Package: Date/time related
Operating System: Linux
PHP Version: 7.2.0RC6
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
Yeah I ran into this too today :-(
https://3v4l.org/jFOkA
Previous Comments:
------------------------------------------------------------------------
[2017-11-29 16:55:52] martin at algorhythm dot de
I have exactly the same problem with another datestring. The datestring I used is
'2017-11-29T15:10:24.123+01:00'.
IMHO I have to use \DateTime::RFC3339_EXTENDED. When I call
\DateTime::format(RFC3339_EXTENDED) it results exactly in my used datestring.
See: https://3v4l.org/TK1oK
------------------------------------------------------------------------
[2017-11-27 19:28:22] mariano@php.net
PHP's PR with failing test: https://github.com/php/php-src/pull/2945
Fix in timelib: https://github.com/derickr/timelib/pull/29
------------------------------------------------------------------------
[2017-11-27 17:33:54] mariano@php.net
Pull request with fix and test: https://github.com/php/php-src/pull/2945
------------------------------------------------------------------------
[2017-11-27 03:57:31] php-bugs at dennis dot birkholz dot biz
Description:
------------
DateTime::createFromFormat(), DateTimeImmutable::createFromFormat() and date_create_from_format()
fail to create a DateTime(Immutable) object when the format is RFC3339_EXTENDED and a valid date
string is supplied but using the constructors / date_create() works.
See https://3v4l.org/shJD7
Test script:
---------------
<?php
$datestring = '2017-06-03T00:08:10.881UTC';
if ($date = DateTime::createFromFormat(DateTime::RFC3339_EXTENDED, $datestring)) {
print_r($date);
} else {
print_r(DateTime::getLastErrors());
}
if ($date = new DateTime($datestring)) {
print_r($date);
} else {
print_r(DateTime::getLastErrors());
}
Expected result:
----------------
DateTime Object
(
[date] => 2017-06-03 00:08:10.881000
[timezone_type] => 3
[timezone] => UTC
)
DateTime Object
(
[date] => 2017-06-03 00:08:10.881000
[timezone_type] => 3
[timezone] => UTC
)
Actual result:
--------------
Array
(
[warning_count] => 0
[warnings] => Array
(
)
[error_count] => 2
[errors] => Array
(
[20] => The format separator does not match
[21] => The timezone could not be found in the database
)
)
DateTime Object
(
[date] => 2017-06-03 00:08:10.881000
[timezone_type] => 3
[timezone] => UTC
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75577&edit=1