6

I am looking for an online tool that checks if a string is ISO8601 compliant. I am not just interested in the timestamp part, but also durations. So all of these should be considered valid:

2007-03-01T13:00:00Z/2008-05-11T15:30:00Z
P1Y2M10DT2H30M/2008-05-11T15:30:00Z
P1Y2M10DT2H30M
2007-11-13/15
2007-11-13T09:00/15T17:00

Preferably it should cover the complete ISO8601-standard.

2

This isn't exactly what you're after but feel free to modify as needed (I just whipped it up).

http://jsfiddle.net/wq7tjec7/14/

If you enter a date string in the input field in the bottom right box and press Test it will attempt to validate your date.

Valid Dates should pass and indicate such, but invalid dates like:

2015-13-05T12:35:45Z

should fail because there is no 13th month.

It will split your incomming string by / characters to enable a range of dates.

2007-03-01T13:00:00Z/2008-05-11T15:30:00Z

However it will not pass P1Y2M10DT2H30M as a valid date (I was not aware at the time I wrote this that this format was valid)

  • Read the standard or at the very least the Wikipedia page if you have any doubt whether a string is valid ISO8601. – Ole Tange Jun 3 '15 at 21:57
  • @OleTange in the last 10 years that I've used ISO8601 dates I haven't once used ranges so I apologize for not realizing there was a syntax for them. If the tool I created above is helpful for you I can certainly improve it to handle the date ranges. – scunliffe Jun 4 '15 at 11:29
  • 2
    FYI, the P1Y2M10DT2H30M value is not a date, it is a period or duration (terms are not standardized). A period/duration is a span of time not tied to the timeline. For example, in the US lunchtime is PT30M while in France it is PT2H. A good date-time library like Joda-Time can add or subtract the period/duration to a specific date-time value tied to the timeline. – Basil Bourque Jun 26 '15 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.