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:
- The date separator character may be a hyphen, slash (/), period, or empty string (omitted). The two date separators must match.
- The time separator character may be a colon, a period, a space, or empty string (omitted). The two time separators must match.
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?
|
|---|