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: 2018-10-09 10:10 UTC
Votes:14
Avg. Score:3.7 ± 1.1
Reproduced:13 of 14 (92.9%)
Same Version:5 (38.5%)
Same OS:10 (76.9%)
From: php-bugs at dennis dot birkholz dot biz Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.2.0RC6 OS: Linux
Private report: No CVE-ID: None
 [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

Pull Requests

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.
 [2018-10-08 13:28 UTC] mail at ciaranmcnulty dot com
We just got hit by this too - it looks like support for `v` and the constant were added for format(), but no changes in createFromFormat (and nothing on the docs pages about `v`).

It's not apparent to someone using the constant why anything would be wrong
 [2018-10-09 10:07 UTC] derick@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=43f7a5735cbc50c885f6563d63591a684528b4d0
Log: Fixed bug #75577: DateTime::createFromFormat does not accept 'v' format specifier, by updating timelib to 2018.01alpha2
 [2018-10-09 10:07 UTC] derick@php.net
-Status: Assigned +Status: Closed
 [2018-10-09 10:09 UTC] derick@php.net
Automatic comment on behalf of github@derickrethans.nl
Revision: http://git.php.net/?p=php-src.git;a=commit;h=09340ea9b9b2a06c6f1369502806640779073885
Log: Fixed bug #75577: DateTime::createFromFormat does not accept 'v' format specifier, by updating timelib to 2018.01alpha2
 [2018-10-09 10:10 UTC] derick@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

Fixed for PHP 7.3RC3 (or RC4).
 [2020-12-07 13:26 UTC] alexwriter2003 at gmail dot com
Snapshots of the sources are packaged every three hours; this https://goo.gl/2DqXGj change
It's not apparent to someone using the constant why anything would be wrong
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC