Bug 16053 – SysTime.fromIsoExtString don't work if nanoseconds are presented
Status
RESOLVED
Resolution
FIXED
Severity
trivial
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-05-21T19:52:43Z
Last change time
2018-01-05T13:28:44Z
Assigned to
No Owner
Creator
Tomáš Chaloupka
Comments
Comment #0 by chalucha — 2016-05-21T19:52:43Z
Just came across the REST API which returns time in format like this: 2016-05-21T14:13:25.032937439Z
Which results in Invalid ISO Extended String exception.
Accoording to wikipedia, there is no limit for decimal fraction:
"There is no limit on the number of decimal places for the decimal fraction. However, the number of decimal places needs to be agreed to by the communicating parties."
There is this check in a fracSecsFromISOString method:
enforce(!str.empty && str.length <= 7, new DateTimeException("Invalid ISO String"));
It would be nice if this method can handle this kind of input strings even though that nanoseconds would be thrown away (probably should be documented behaviour)
Is this legit?
Comment #1 by issues.dlang — 2017-05-11T20:33:21Z
Yes, it's legit. It's just that SysTime will never produce a string with more than 7 digits in the fractional seconds, because its precision is hecto-nanoseconds, and for whatever reason, it didn't occur to me that I would need handle higher precision from elsewhere (even though it should have). It should be a simple enough fix though.
Comment #3 by github-bugzilla — 2017-05-17T03:13:14Z
Commit pushed to master at https://github.com/dlang/phoboshttps://github.com/dlang/phobos/commit/21c09f18d33b65475a89c7d6ec75d87556e6c1e5
Issue 16053: Fix it so that SysTime's from*String supports more than 7 digits.
ISO 8601 says that it's up to the application to decide how many digits
to put in the fractional seconds if they're present. SysTime.to*String
puts up to 7 (stripping trailing zeroes), because that's
hecto-nanosecond precision, and SysTime holds the time in
hecto-nanoseconds. Currently, from*String only accepts up to 7 digits in
the fractional seconds, which _does_ follow the spec in that (per the
spec) the number of digits is up to the applications. However, while we
never emit more than 7 digits, other applications do, so only accepting
7 digits makes us incompatible with them, whereas accepting them would
make us more compatible with other programs, and it would actually be
more efficient, since we'd have fewer checks in the code.
So, these changes make is so that SysTime.from*String accepts more than 7
digits in the fractional seconds, but the additional digits are
truncated (since SysTime doesn't support more than 7 digits of
precision).
Comment #4 by github-bugzilla — 2017-06-17T11:34:44Z