php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #71345 DateTime::__construct failed to parse fraction with more than 9 digits.
Submitted: 2016-01-12 06:22 UTC Modified: 2016-01-12 06:38 UTC
Votes:3
Avg. Score:4.0 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: iceberg_young at 126 dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 7.0.2 OS: Any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-01-12 06:22 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-12 06:38 UTC] requinix@php.net
-Type: Bug +Type: Feature/Change Request
 [2016-01-12 08:43 UTC] salsi at icosaedro dot it
Might be related to bug #69122 "strtotime and DateTime fail to parse certain strings with fractional seconds".
 [2016-06-14 11:18 UTC] 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)
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Sep 23 13:01:27 2019 UTC