Improve ISO8601 date/time class string format templates.


The current string templates, e.g.

YYYY-MM-DDThh:mm:ss[,sss][Z | ±hh[mm]]

as seen in the various ISO8601 classes starting here:

are not clear with respect to fractional seconds (which can be any number of digits from 1 to 6) and also not formal, as would be a regex.

Also, the current ISO8601_TIMEZONE does not support ':' in extended format, but this is required by the standard.



Thomas Beale
March 3, 2016, 12:11 AM

The partial options are all spelled out as separate possibilities in the class documentation.

I was told that the max fractional second digits are 6, but just checked the standard, which says this:
"The decimal fraction shall at least have one digit, the maximum number of digits in the decimal component needs to be agreed by the partners in information interchange."

The standard uses an underlined 's' to mean a variable number of digits, whereas say 'hhmm' means exactly 4 digits. So I propose to change the templates to follow the standard. Underlined characters are not any kind of standard, but it does make the templates easy to read, and compliant with the standard, and it can be explained by a sentence at the top of the section.

I had thought also of using regexes, but they get complicated fast, and either we have to create multiple regexes for all the patterns, or else change the documentation to just use one regex, which is pretty close to unreadable. In Release 1.1.0, we could additionally add some regexes, but I'm not sure if its work the effort of working them out now (different implems will probably use different regexes anyway, depending on how they deal with the partial forms).

Koray Atalag
March 4, 2016, 2:34 AM

There's no hard limit of 6 - it's just to allow for microseconds. I reckon most programming languages allow up to 9 digits that is nanoseconds. I guess the point is not to restrict to any digit in the RM as per the ISO spec. Implementers, naturally, may want to have some practical limits - 6 is a reasonable one IMHO.

Thomas Beale
March 4, 2016, 10:26 AM

Note that I have updated the format to be a pseudo-regex one, so now it looks like:


i.e. [(,|.)s+] stands for the optional fractional seconds.

There is now also a comment at the top of the section to explain this usage.

Heath Frankel
March 8, 2016, 12:58 PM

Where is this commit? The reference commit appears to be the one with the excessive options.

Pablo Pazos
April 28, 2016, 3:18 AM


We mentioned the extended format uses : in the TZ

The proposed regex by Thomas has the extended format but the TZ doesn't have the :

IMO it should be:

YYYY-MM-DDThh:mm:ss±hh:mm Example: 1985-04-12T10:15:30+04:00
YYYY-MM-DDThh:mm:ss±hh Example: 1985-04-12T10:15:30+04


Thomas Beale

Raised By

Koray Atalag


Affects versions