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:3
Avg. Score:3.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
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
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC