Req #53831 [Com]: DateInterval constructor does not handle valid ISO 8601 strings
| From: | jens dot hassler at gmail dot com | Date: | Mon, 19 Apr 2021 18:33:28 +0000 |
| Subject: | Req #53831 [Com]: DateInterval constructor does not handle valid ISO 8601 strings | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233513@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53831&edit=1
ID: 53831
Comment by: jens dot hassler at gmail dot com
Reported by: pallinger at dsd dot sztaki dot hu
Summary: DateInterval constructor does not handle valid ISO
8601 strings
Status: Not a bug
Type: Feature/Change Request
Package: Date/time related
Operating System: ubuntu linux 10.10
PHP Version: 5.3.5
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
Actually, as stated before, the standard allows fractions in the lowest part of the interval. Today
I stumbled upon this when implementing an API to Polar watches. They actually send duration strings
like "PT13724.627S", which seems to be ok by the RFC, but results in a "unknown or
bad format" error in PHP.
I really think this is a bug and not a feature request.
Previous Comments:
------------------------------------------------------------------------
[2020-03-29 04:31:03] pegasus at vaultwiki dot org
For reference, here is a more recent version of ISO 8601 that I've found (from 2000). http://xml.coverpages.org/ISO-FDIS-8601.pdf
The relevant section is 5.5.3. It states:
"If necessary for a particular application the lowest order component may have a decimal
fraction. The decimal
fraction shall be divided from the integer part by the decimal sign specified in ISO 31-0: i.e. the
comma [,] or
full stop [.]. Of these, the comma is the preferred sign. The decimal fraction shall at least have
one digit. If the
magnitude of the number is less than unity, the decimal sign shall be preceded by a zero (see ISO
31-0)."
------------------------------------------------------------------------
[2020-03-28 22:56:38] pegasus at vaultwiki dot org
According to the RFC cited as the reason for closing this report:
"This information is based on the 1988 version of ISO 8601. There may
be some changes in the 2000 revision."
However, when discussing the basis for the accepted formats for DateInterval, the PHP documentation
(https://www.php.net/manual/en/dateinterval.construct.php) links not to the cited RFC but to the
Wikipedia page for ISO 8601, which reflects more recent versions of the ISO that were written after
1988. If PHP devs insist this is not a bug, then the documentation should be updated to point to the
RFC, and not to a page that discusses features of the ISO that PHP has not implemented.
------------------------------------------------------------------------
[2020-02-28 00:58:09] googleguy@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Closing.
This feature won't be implemented in php at the current time.
------------------------------------------------------------------------
[2020-02-27 19:12:44] googleguy@php.net
This may be considered more of a feature request than a bug, however, I'm assigning to Derrick
and pinging them here.
When I looked at "Appendix A. ISO 8601 Collected ABNF" of RFC3339, I only see the
definition of Seconds Duration as DIGIT, not fraction:
Durations:
dur-second = 1*DIGIT "S"
dur-minute = 1*DIGIT "M" [dur-second]
dur-hour = 1*DIGIT "H" [dur-minute]
dur-time = "T" (dur-hour / dur-minute / dur-second)
dur-day = 1*DIGIT "D"
dur-week = 1*DIGIT "W"
dur-month = 1*DIGIT "M" [dur-day]
dur-year = 1*DIGIT "Y" [dur-month]
dur-date = (dur-day / dur-month / dur-year) [dur-time]
Additionally, section 5.3 of the RFC may seem to indicate that this not required by the
specification:
---
5.3. Rarely Used Options
A format which includes rarely used options is likely to cause
interoperability problems. This is because rarely used options are
less likely to be used in alpha or beta testing, so bugs in parsing
are less likely to be discovered. Rarely used options should be made
mandatory or omitted for the sake of interoperability whenever
possible.
The format defined below includes only one rarely used option:
fractions of a second. It is expected that this will be used only by
applications which require strict ordering of date/time stamps or
which have an unusual precision requirement.
---
However, I'll leave this to Derick to decide. It does seem to be a highly sought after feature
and it would make sense to add it in the interval spec.
Derick, any thoughts on this?
------------------------------------------------------------------------
[2019-01-10 19:15:05] mdwyer at michaelmdwyer dot com
This appears to still be an issue with PHP 7.2, despite them adding a microseconds field to
DateInterval. My current workaround is:
$fractional = new DateInterval('PT0S');
$fractional->f = ".{$microseconds}";
$fractional->invert = $seconds < 0;
return (new DateTime("@{$seconds}"))->add($fractional);
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=53831
--
Edit this bug report at https://bugs.php.net/bug.php?id=53831&edit=1