[Rt-commit] rt branch, 4.4/improved-parsing-of-iso-8601-dates, created. rt-4.4.4-137-g1965cb2140

Dianne Skoll dianne at bestpractical.com
Wed Aug 26 10:12:27 EDT 2020


The branch, 4.4/improved-parsing-of-iso-8601-dates has been created
        at  1965cb2140032cce5d7ac73ac5e34e00c276beec (commit)

- Log -----------------------------------------------------------------
commit 1965cb2140032cce5d7ac73ac5e34e00c276beec
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
    Now it can also handle:        yyyy-mm-ddThh:mm:ss
    as well as:                    yyyy-mm-ddThh:mm:ssZ

diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index e76ae707d8..710362050c 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -173,7 +173,7 @@ sub Set {
     }
     elsif (
         ($format eq 'sql' || $format eq 'iso')
-        && $args{'Value'} =~ /^(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/
+        && $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;
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