Req #71345 [Com]: DateTime::__construct failed to parse fraction with more than 9 digits.

From: Date: Mon, 09 Nov 2020 11:24:00 +0000
Subject: Req #71345 [Com]: DateTime::__construct failed to parse fraction with more than 9 digits.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230219@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71345&edit=1

 ID:                 71345
 Comment by:         jan dot espen dot oversand at cerpus dot com
 Reported by:        iceberg_young at 126 dot com
 Summary:            DateTime::__construct failed to parse fraction with
                     more than 9 digits.
 Status:             Open
 Type:               Feature/Change Request
 Package:            Date/time related
 Operating System:   Any
 PHP Version:        7.0.2
 Block user comment: N
 Private report:     N

 New Comment:

Unfortunately I don't have the resources available to verify with a build of php-src right now.

But, I think, maybe this is related to the max length of 8 at line 1245 of https://github.com/php/php-src/blob/master/ext/date/lib/parse_date.re

time->us = timelib_get_frac_nr(&ptr, 8);

Maybe if that was increased to at least 9 (nanosecond) precision. Other systems are doing nanosecond
precision and interoperability problems will occur with this limitation.


Previous Comments:
------------------------------------------------------------------------
[2016-06-14 11:18:43] mkroese at eljakim dot nl

Encountered this one today too, while parsing actual timestamps received from another party.

Following paste shows it still works up to 8 digits, and fails at 9 (without a timezone suffix,
which makes the error message even more cryptic):
https://3v4l.org/pMvig

It also shows that the fraction isn't handled correctly with 8 digits (23:59:59.1000000)

------------------------------------------------------------------------
[2016-01-12 08:43:47] salsi at icosaedro dot it

Might be related to bug #69122 "strtotime and DateTime fail to parse certain strings with
fractional seconds".

------------------------------------------------------------------------
[2016-01-12 06:22:18] iceberg_young at 126 dot com

Description:
------------
DateTime::__construct cannot parse [W3] datetime format with fraction of second has more than **9**
digits.
E.g.
	new \DateTime("2016-01-01T01:02:03.123456789-01:02");
will fail, while
	new \DateTime("2016-01-01T01:02:03.12345678-01:02");
is ok.

Tried PHP version: 5.5.26 and 7.0.2
Tried OS: CentOS 6.7, openSUSE Tumbleweed, Windows 7

---

[W3]: http://www.w3.org/TR/NOTE-datetime-970915

Test script:
---------------
<?php
$w3 = new \DateTime("2016-01-01T01:02:03.123456789-01:02");
echo $w3->format("Y-m-d\TH:i:s.uP");

Expected result:
----------------
(No exception throw!)
2016-01-01T01:02:03.123457-01:02

Actual result:
--------------
PHP Warning:  Uncaught exception 'Exception' with message 'DateTime::__construct():
Failed to parse time string (2016-01-01T01:02:03.123456789-01:02) at position 0 (2): The timezone
could not be found in the database' in php shell code:1


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=71345&edit=1


Thread (5 messages)

« previous php.bugs (#230219) next »