1nickt has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

The doc for Regexp::Common::time ISO8601 datetimes states:

However the standard for an ISO8601 datetime appears to additionally require that if a separator is used for the date or the time, a separator must also be used for the other component. I cannot find a spec that states this, but read on ...

Demonstrated with DateTime::Format::ISO8601 :

$ perl -Mstrict -MRegexp::Common=time -MDateTime::Format::ISO8601 -wE +' my $str = "2018-03-01T110601Z"; say "DateTime::Format: ", eval { my $dt = DateTime::Format::ISO8601->p +arse_datetime($str) } ? "valid" : "not valid: $@"; say "Regexp::Common: ", $str =~ /$RE{time}{iso}/ ? "valid" : "not vali +d"; ' DateTime::Format: not valid: Invalid date format: 2018-03-01T110601Z a +t -e line 3. eval {...} called at -e line 3 Regexp::Common: valid

Control:

$ perl -Mstrict -MRegexp::Common=time -MDateTime::Format::ISO8601 -wE +' my $str = "2018-03-01T11:06:01Z"; say "DateTime::Format: ", eval { my $dt = DateTime::Format::ISO8601->p +arse_datetime($str) } ? "valid" : "not valid: $@"; say "Regexp::Common: ", $str =~ /$RE{time}{iso}/ ? "valid" : "not vali +d"; ' DateTime::Format: valid Regexp::Common: valid

Which is right?


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re: Does ISO8601 require a separator in the time if one is used in the date?
by hippo (Archbishop) on Mar 02, 2018 at 09:42 UTC

      Thanks hippo, it's a good point and in general a good rule. The problem is that if we accept scruffy datetimes with Regexp::Common::time then we can't parse them to prep for DB insertion using DateTime::Format::ISO8601 and the parsing becomes more complicated than it should be. Maybe the cleanest way would be to write a class that uses both of those modules and provides a single interface.


      The way forward always starts with a minimal test.
Re: Does ISO8601 require a separator in the time if one is used in the date?
by Eily (Monsignor) on Mar 01, 2018 at 16:46 UTC

    From Wikipedia:

    Either basic or extended formats may be used, but both date and time must use the same format.
    (Basic format meaning without separators). There's no citation to go with it though.

      On the other hand, DateTime::Format::ISO8601 does have a citation: Section 5.4 of ISO 8601:2000(E).

      Thanks Eily. I had seen that, but frankly I'd rank DateTime modules above Wikipedia as an authority. I'm hoping someone can point to the spec, although I've looked at that in various places as well.


      The way forward always starts with a minimal test.
        I'd rank DateTime modules above Wikipedia as an authority

        Well in this case they agree anyway :) . But I guess nothing beats a direct citation from the spec.

        I can't even find a single RFC that refers to this forced condition. Now I've started, I'm curious to find something myself here if possible...