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

From: Date: Tue, 25 Feb 2020 13:35:03 +0000
Subject: Bug #79305 [Opn]: DateTimeImmutable::createFromFormat() does not permit decimal point in Atom
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225720@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 Type: Bug Package: Date/time related Operating System: Linux (Debian) PHP Version: Irrelevant Block user comment: N Private report: N New Comment: See https://github.com/php/php-src/pull/4934 Previous Comments: ------------------------------------------------------------------------ [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 (#225720) next »