[Rt-commit] rt branch, 4.4/improved-parsing-of-iso-8601-dates, created. rt-4.4.4-144-g071ca54e3e
Dianne Skoll
dianne at bestpractical.com
Thu Oct 1 17:03:14 EDT 2020
The branch, 4.4/improved-parsing-of-iso-8601-dates has been created
at 071ca54e3e7aceca0e5cede39b361c67027a7dfd (commit)
- Log -----------------------------------------------------------------
commit 071ca54e3e7aceca0e5cede39b361c67027a7dfd
Author: Dianne Skoll <dianne at bestpractical.com>
Date: Wed Aug 26 10:08:51 2020 -0400
Tweak RT::Date to parse ISO-8601 combined date and time representations.
The old code would not parse a date formatted as described at
https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations
Before, the code would handle: yyyy-mm-dd hh:mm:ss
Currently, it handles the following six specific formats:
yyyy-mm-dd hh:mm:ss
yyyy-mm-dd hh:mm:ssZ
yyyy-mm-ddThh:mm:ss
yyyy-mm-ddThh:mm:ssZ
yyyymmddThhmmss
yyyymmddThhmmssZ
diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index e76ae707d8..8ace3a0d1b 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -171,10 +171,16 @@ sub Set {
if ( $format eq 'unix' ) {
return $self->Unix( $args{'Value'} );
}
- elsif (
- ($format eq 'sql' || $format eq 'iso')
- && $args{'Value'} =~ /^(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/
- ) {
+ elsif ($format eq 'sql' && $args{'Value'} =~ /^(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/) {
+ local $@;
+ my $u = eval { Time::Local::timegm($6, $5, $4, $3, $2-1, $1) } || 0;
+ $RT::Logger->warning("Invalid date $args{'Value'}: $@") if $@ && !$u;
+ return $self->Unix( $u > 0 ? $u : 0 );
+ }
+ elsif
+ ( $format eq 'iso' &&
+ ( $args{'Value'} =~ /^(\d{4})-(\d\d)-(\d\d)[ T](\d\d):(\d\d):(\d\d)Z?$/ ||
+ $args{'Value'} =~ /^(\d{4})(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)Z?$/)) {
local $@;
my $u = eval { Time::Local::timegm($6, $5, $4, $3, $2-1, $1) } || 0;
$RT::Logger->warning("Invalid date $args{'Value'}: $@") if $@ && !$u;
diff --git a/t/api/date.t b/t/api/date.t
index 4a3851e689..434049b4c4 100644
--- a/t/api/date.t
+++ b/t/api/date.t
@@ -292,6 +292,12 @@ my $year = (localtime(time))[5] + 1900;
$date->Set(Format => 'ISO', Value => '2005-11-28 15:10:00');
is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
+ $date->Set(Format => 'ISO', Value => '2005-11-28T15:10:00');
+ is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
+
+ $date->Set(Format => 'ISO', Value => '2005-11-28T15:10:00Z');
+ is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
+
$date->Set(Format => 'ISO', Value => '2005-11-28 15:10:00+00');
is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss+00");
-----------------------------------------------------------------------
More information about the rt-commit
mailing list