CC: | tonkin [...] cpan.org |
Subject: | Invalid ISO8601 datetimes are being matched OK |
Date: | Thu, 1 Mar 2018 11:38:34 -0500 |
To: | bug-regexp-common-time [...] rt.cpan.org |
From: | Nick Tonkin <nick.tonkin [...] endurance.com> |
Hi Mohammad,
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 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->parse_datetime( $str ) } ? "valid" : "not valid:
$@";
say "Regexp::Common: ", $str =~ /$RE{time}{iso}/ ? "valid" : "not valid";
'
DateTime::Format: not valid: Invalid date format: 2018-03-01T110601Z at -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->parse_datetime( $str ) } ? "valid" : "not valid:
$@";
say "Regexp::Common: ", $str =~ /$RE{time}{iso}/ ? "valid" : "not valid";
'
DateTime::Format: valid
Regexp::Common: valid
Thank you,
- nick
--
Nick Tonkin
Software Engineer