php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79305 DateTimeImmutable::createFromFormat() does not permit decimal point in Atom
Submitted: 2020-02-25 12:44 UTC Modified: 2020-02-28 10:04 UTC
From: xedin dot unknown at gmail dot com Assigned: heiglandreas (profile)
Status: Closed Package: Date/time related
PHP Version: Irrelevant OS: Linux (Debian)
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: xedin dot unknown at gmail dot com
New email:
PHP Version: OS:

 

 [2020-02-25 12:44 UTC] xedin dot unknown at gmail dot com
Description:
------------
`DateTimeImmutable::createFromFormat()` does not appear to allow timestamps in Atom (RFC 3339) format to have a decimal point for time units. RFC 3339 derives the relevant specification from ISO-8601, which states:

> A decimal mark, either a comma or a dot [...] is used as a separator between the time element and its fraction

Alas, when trying to parse such a timestamp, `createFromFormat()` returns `false`, which is a bug of its own (https://bugs.php.net/bug.php?id=64923).

See it in action here: https://3v4l.org/OSfKR

Interestingly, when creating a date from a timestamp without the decimal part, the resulting instance has the `$date` property set to `2019-10-10 15:32:38.000000`, which does in fact contain the decimal part. This probably means that internally, PHP does cater for fractions.

Test script:
---------------
$dateString = '2019-10-10T15:32:38.916Z';
$date = \DateTimeImmutable::createFromFormat(DATE_ATOM, $dateString);

if (!($date instanceof \DateTimeInterface)) {
    throw new RangeException('Looks like PHP cannot parse decimals in time segment');
}

Expected result:
----------------
No exception is thrown.

Actual result:
--------------
An exception is thrown, indicating that a date instance could not be produced from the timestamp.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-02-28 10:04 UTC] heiglandreas@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: heiglandreas
 [2020-02-28 10:04 UTC] heiglandreas@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The described issue works as intended with the given Constant.

For a workaround use either a dedicated format-string or pass the value directly to the constructor of DateTimeImmutable as shown in https://3v4l.org/sanKD
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 00:01:28 2024 UTC