php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66019 DateTime object does not support short ISO 8601 time format - YYYY-MM-DDTHH
Submitted: 2013-11-02 00:25 UTC Modified: 2021-04-07 12:42 UTC
From: kaldari at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.5.5 OS: MacOS X
Private report: No CVE-ID: None
 [2013-11-02 00:25 UTC] kaldari at gmail dot com
Description:
------------
According to ISO 8601, the following is a valid date-time representation:
2012-02-02T10
(representing 2 February 2012, 10:00)

However, PHP throws an error if the minutes are not specified.

Test script:
---------------
$tz = new DateTimeZone("Europe/Amsterdam");
$dateObject = new DateTime( '2012-02-02T10', $tz );
echo $dateObject->format( 'j F Y H:i' );

Expected result:
----------------
2 February 2012 10:00

Actual result:
--------------
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (2012-02-02T10) at position 11 (1): Unexpected character'

Patches

bug66019.patch (last revision 2016-08-07 16:35 UTC by cmb@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-03 11:43 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2016-08-07 16:35 UTC] cmb@php.net
The following patch has been added/updated:

Patch Name: bug66019.patch
Revision:   1470587717
URL:        https://bugs.php.net/patch-display.php?bug=66019&patch=bug66019.patch&revision=1470587717
 [2016-08-07 16:35 UTC] cmb@php.net
-Status: Assigned +Status: Verified
 [2016-08-07 16:35 UTC] cmb@php.net
Confirmed: <https://3v4l.org/Wpjs0>.

However, not only YYYY-MM-DDThh is allowed by ISO 8601, but also
hh, and as the date time parser is rather liberal wrt. its input,
also h would make sense. The respective fix is trivial (see
bug66019.patch), but it would now allow some somewhat doubtful
input to be successfully parsed, for instance, '3' (=> 03:00:00)
and '03-03' (=> 03:00:00-03:00). Not sure, if that's desirable.

Derick, what do you think?
 [2017-10-24 05:24 UTC] kalle@php.net
-Status: Verified +Status: Assigned
 [2021-04-07 09:34 UTC] derick@php.net
@cmb, your patch breaks:

derick@gargleblaster:~/dev/derickr-timelib$ ./tests/tester-parse-string "14/10/2006"
E=2 TS: 0 | -99999-10-20 14:00:00
Errors found while parsing '14/10/2006'
E Unexpected character @ pos 2 (char=[/])
E Double time specification @ pos 8 (char=[0])

derick@gargleblaster:~/dev/derickr-timelib$ ./tests/tester-parse-string "13/10/2006"
E=2 TS: 0 | -99999-10-20 13:00:00
Errors found while parsing '13/10/2006'
E Unexpected character @ pos 2 (char=[/])
E Double time specification @ pos 8 (char=[0])

So unless you're really invested in this, I'm likely to close this.
 [2021-04-07 12:42 UTC] cmb@php.net
Ah, yes, this patch is way to general; it doesn't make sense to
support stand alone hours.  Still, I think the date parser should
support ISO 8061 YYYY-MM-DDTHH.  I submitted a draft PR:
<https://github.com/derickr/timelib/pull/106>.
 [2022-05-20 12:25 UTC] git@php.net
Automatic comment on behalf of derickr
Revision: https://github.com/php/php-src/commit/ee2776210b97e3addb8c981d3ae800db8c1e0031
Log: Fixed bug #66019 (DateTime object does not support short ISO 8601 time format - YYYY-MM-DDTHH)
 [2022-05-20 12:25 UTC] git@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC