Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #568 (closed enhancement: fixed)

Opened 12 years ago

Last modified 12 years ago

TimeStamp.iso8601 is too limited

Reported by: Deewiant Assigned to: kris
Priority: normal Milestone: 0.99.3
Component: Core Functionality Version: trunk
Keywords: Cc:


Kris mentioned this in Ticket #562: tango.text.convert.TimeStamp?.iso8601 only parses one format, "YYYY-MM-DD hh:mm:ss,sss".

That isn't even actually in the standard: there should be a 'T' between the date and the time, not a space.

I hereby submit a 1200-line module with 500 lines of unit tests, based on the ISO 8601:2004 standard (described in a PDF Wikipedia links to), which has functions for parsing almost every date/time format specified.

The ones they don't parse are intervals, durations, and recurring intervals, because I got too lazy to implement them.

The functions (iso8601Time, iso8601Date, and iso8601) update a Date passed. Not a Time, as does the current iso8601, because that's too limited a format. One can always convert to a Time if necessary, keeping in mind that information loss might occur if the Date is outside the interval Time can represent.

In addition, because its dayOfWeek function only works for 1900-3-1 to 2100-2-28, it'd fail by a day or two on ISO week dates outside that interval. (Currently it asserts outside 1901-2099.) If somebody knows a good algorithm which would fix that, by all means submit it.

Another thing it doesn't do is conversions from local time to UTC if the time parsed starts with a 'T'. A comment in doIso8601Time() explains why.

Because the Date struct has no support for time zones, the module just converts times with specified time zones into UTC. This leads to behaviour which may or may not be a bug, as explained in a comment in getTimeZone().

Feel free to ask questions or offer suggestions: the code is IMO mostly clear but there are definitely some places where it could be improved.


iso8601.d (28.9 kB) - added by Deewiant on 08/10/07 13:43:06.

Change History

08/10/07 13:43:06 changed by Deewiant

  • attachment iso8601.d added.

08/28/07 06:19:45 changed by kris

  • status changed from new to assigned.

Awesome -- thanks Deewiant!

I'll take a look, and pass it around the other guys too ...

08/30/07 18:58:45 changed by kris

Copied into tango.scrapple, though this will likely be inserted into tango.util.time somewhere

10/12/07 08:18:38 changed by larsivi

  • status changed from assigned to closed.
  • type changed from defect to enhancement.
  • resolution set to fixed.
  • milestone changed from 1.0 to 0.99.3.

Added into Tango, tango.util.time.ISO8601 in [2645]. Thanks Deewiant!