Bug #79305 [Opn->Csd]: DateTimeImmutable::createFromFormat() does not permit decimal point in Atom

From: Date: Fri, 28 Feb 2020 10:04:22 +0000
Subject: Bug #79305 [Opn->Csd]: DateTimeImmutable::createFromFormat() does not permit decimal point in Atom
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225771@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79305&edit=1 ID: 79305 Updated by: heiglandreas@php.net Reported by: xedin dot unknown at gmail dot com Summary: DateTimeImmutable::createFromFormat() does not permit decimal point in Atom -Status: Open +Status: Closed Type: Bug Package: Date/time related Operating System: Linux (Debian) PHP Version: Irrelevant -Assigned To: +Assigned To: heiglandreas Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2020-02-25 13:35:03] heiglandreas@php.net See https://github.com/php/php-src/pull/4934 ------------------------------------------------------------------------ [2020-02-25 12:44:43] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79305&edit=1

« previous php.bugs (#225771) next »