|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51987 Datetime fails to parse an ISO 8601 ordinal date (extended format)
Submitted: 2010-06-03 13:55 UTC Modified: 2022-05-13 13:10 UTC
Avg. Score:3.3 ± 1.2
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jbondc at openmv dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.1 OS: FreeBSD
Private report: No CVE-ID: None
 [2010-06-03 13:55 UTC] jbondc at openmv dot com
PHP 5.2.12 with Suhosin-Patch 0.9.7 (cli) (built: Dec 30 2009 15:41:26) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
    with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies

Test script:
// Ordinal date — 12 April 1985

$d1 = new Datetime('1985102');
// OK

$d2 = new Datetime('1985-102');
// Exception: DateTime::__construct(): Failed to parse time string (1985-102) at position 7 (2): Unexpected character


Implementation_with_various_bug_fixes (last revision 2011-01-26 21:41 UTC by jbondc at openmv dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-03 14:36 UTC]
-Status: Open +Status: Bogus
 [2010-06-03 14:36 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Currently only YYdoy and YY.doy are supported. Adding in YY-doy would conflict 
with existing support for YY-mm. See for details 
of what is currently available.

(Key: YY = four-digit year, doy = day of year, mm = month number.)
 [2010-06-03 14:55 UTC] jbondc at openmv dot com
Please leave this bug open, I will look at submitting a patch.

There is no reason not to support:

$d2 = new Datetime('1985-001');
$d2 = new Datetime('1985-002');
$d2 = new Datetime('1985-365');


$d2 = new Datetime('1985-01');
$d2 = new Datetime('1985-12');
 [2010-06-03 15:04 UTC]
-Status: Bogus +Status: Open -Type: Bug +Type: Feature/Change Request
 [2010-06-03 15:04 UTC]
It's a feature request though, *but* before we add it we must be certain that it doesn't conflict.
 [2010-06-03 15:38 UTC]
Forgive my initial hastiness, I overlooked the fact that doy should always be 3-
digits in length. Sorry!!
 [2011-01-26 22:49 UTC] jbondc at openmv dot com
This patch needs:
re2c -d -b -o ext/date/lib/parse_date.c ext/date/lib/

It also fixes tests that were failing in trunk.

I changed the behavior of timelib_parse_from_format() to always initialized seconds, minutes, hours to 0 if they are not set.
 [2017-03-11 21:37 UTC]
-Assigned To: +Assigned To: derick
 [2017-03-11 21:37 UTC]
@derick Any chance we can merge this patch or close this as "Wont fix"?
 [2017-03-11 21:37 UTC]
-PHP Version: 5.2.13 +PHP Version: 7.1
 [2017-03-11 22:37 UTC]
patches to timelib need to have a PR made against:
 [2022-05-13 13:10 UTC]
-Status: Assigned +Status: Closed
 [2022-05-13 13:10 UTC]
Fixed in the through third party timelib library, for inclusion into PHP 8.1.7 (or PHP 8.1.8) and PHP 8.2 and later.
 [2022-05-20 12:25 UTC]
Automatic comment on behalf of derickr
Log: Fixed bug #51987 (Datetime fails to parse an ISO 8601 ordinal date (extended format))
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Mar 28 09:03:46 2023 UTC