Bug 8646 – std.datetime ISO strings are incompatible with ISO 8601

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-12T10:03:00Z
Last change time
2012-09-12T13:49:21Z
Assigned to
nobody
Creator
jens.k.mueller

Comments

Comment #0 by jens.k.mueller — 2012-09-12T10:03:23Z
According to http://en.wikipedia.org/wiki/ISO_8601 ISO 8601 date time strings contain nothing below seconds. But the std.datetime's ISO function contain values for this. Hence, it is currently incompatible with ISO 8601.
Comment #1 by issues.dlang — 2012-09-12T10:38:22Z
It's perfectly legit. Reread the Times section. You can have "decimal fractions" (which is a really screwed up term IMHO, since decimals and fractions are different things, but whatever) to any of the three time elements - including seconds. The number of decimal places to use "needs to be agreed to by the communicating parties," but the notation is correct. If there's a problem, it's the fact that fromISOExtString doesn't accept variants of ISO-8601 that toISOExtString doesn't use (e.g. using a comma instead of a decimal or having decimal fractions for minutes). But they both follow the standard. There are other places online that fractional seconds are discussed as well. e.g. http://www.cl.cam.ac.uk/~mgk25/iso-time.html
Comment #2 by jens.k.mueller — 2012-09-12T12:42:16Z
Thanks for your prompt reply. I see now that the standard allows for fractional seconds. In my use case I'm programming against against a specification that demands ISO 8601 conformity without fractional seconds. Is there an easy way to remove the fractional seconds? Because if there are no then toISOExtString() won't return them. My current workaround is quite tedious for this common operation.
Comment #3 by issues.dlang — 2012-09-12T13:30:04Z
Just strip the fractional seconds from the SysTime by setting its fracSec property to 0. So, something like sysTime.fracSec = FracSec.from!"msecs"(0); (I should probably add a static property to FracSec which gives you 0, but there isn't anything like that right now). Then when you call toISOString or toISOExtString, it doesn't have any fractional seconds, so the resultant string won't have them.
Comment #4 by jens.k.mueller — 2012-09-12T13:49:21Z
Thanks. This looks good.