PHP :: Bug #75577 :: DateTime::createFromFormat does not accept RFC3339_EXTENDED format
php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75577 DateTime::createFromFormat does not accept RFC3339_EXTENDED format
Submitted: 2017-11-27 03:57 UTC Modified: 2017-11-27 13:05 UTC
Votes:13
Avg. Score:3.6 ± 1.1
Reproduced:12 of 13 (92.3%)
Same Version:5 (41.7%)
Same OS:9 (75.0%)
From: php-bugs at dennis dot birkholz dot biz Assigned: derick (profile)
Status: Assigned Package: Date/time related
PHP Version: 7.2.0RC6 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php-bugs at dennis dot birkholz dot biz
New email:
PHP Version: OS:

 

 [2017-11-27 03:57 UTC] 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
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-11-27 13:05 UTC] derick@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2017-11-27 17:33 UTC] mariano@php.net
Pull request with fix and test: https://github.com/php/php-src/pull/2945
 [2017-11-27 19:28 UTC] 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-29 16:55 UTC] 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
 [2018-01-15 16:17 UTC] rob dot bast at gmail dot com
Yeah I ran into this too today :-(

https://3v4l.org/jFOkA
 [2018-01-15 16:18 UTC] rob dot bast at gmail dot com
Sorry that should have been https://3v4l.org/N3UgG *
 [2018-04-19 10:02 UTC] rdohms@php.net
This appears to be due to lack of support for `v` which is part of RFC3339_EXTENDED, so  this ticket could be renamed to include that information and cover a broader lack of the feature.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Tue Aug 14 13:01:25 2018 UTC