[Rt-commit] rt branch, 4.2/extend-iso-date-format, updated. rt-4.2.14-11-g95aa930ad

Jim Brandt jbrandt at bestpractical.com
Fri Jan 26 14:45:22 EST 2018


The branch, 4.2/extend-iso-date-format has been updated
       via  95aa930ad70e26e2f0ca2fdc317c6c77c07ffa84 (commit)
       via  8b6cb94f8876675089a4c811a16ed62d158b25f4 (commit)
      from  be31b6a0b4e9d23f6fcb64f06fff4c99dbfe98a7 (commit)

Summary of changes:
 lib/RT/CustomField.pm | 14 ++++++++++++--
 t/api/customfield.t   | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 2 deletions(-)

- Log -----------------------------------------------------------------
commit 8b6cb94f8876675089a4c811a16ed62d158b25f4
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Jan 26 14:43:43 2018 -0500

    When canonicalizing date, try iso before unknown

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 62afb67cf..a46e5c67e 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1712,8 +1712,18 @@ sub _CanonicalizeValueDateTime {
     my $self    = shift;
     my $args    = shift;
     my $DateObj = RT::Date->new( $self->CurrentUser );
-    $DateObj->Set( Format => 'unknown',
-                   Value  => $args->{'Content'} );
+
+    # Parsing unknown is a heavier operation, so try iso first since that's
+    # what will come from RT's web UI
+    my $ret = $DateObj->Set( Format => 'iso',
+                             Value  => $args->{'Content'} );
+
+    # If ISO didn't work, try to guess
+    unless ( $ret ) {
+        $DateObj->Set( Format => 'unknown',
+                       Value  => $args->{'Content'} );
+    }
+
     $args->{'Content'} = $DateObj->ISO;
     return 1;
 }

commit 95aa930ad70e26e2f0ca2fdc317c6c77c07ffa84
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Jan 26 14:45:11 2018 -0500

    Add tests for _CanonicalizeValueDateTime

diff --git a/t/api/customfield.t b/t/api/customfield.t
index df8f66df2..0ce147b27 100644
--- a/t/api/customfield.t
+++ b/t/api/customfield.t
@@ -1,3 +1,5 @@
+use Test::MockTime qw(set_fixed_time restore_time);
+use DateTime;
 
 use strict;
 use warnings;
@@ -390,5 +392,45 @@ $cf = RT::CustomField->new( RT->SystemUser );
 $cf->LoadByName(Name => 'TestingCF', Queue => 1, IncludeDisabled => 0 );
 ok( ! $cf->id, "Doesn't find it if IncludeDisabled => 0" );
 
+diag('Test _CanonicalizeValueDateTime');
+
+{
+    my %args;
+    my $cf_date = RT::CustomField->new( RT->SystemUser );
+    $args{'Content'} = '2005112815:10:00';
+
+    $cf_date->_CanonicalizeValueDateTime(\%args);
+    is($args{'Content'}, '2005-11-28 15:10:00', "YYYYDDMMhh:mm:ss");
+
+    $args{'Content'} = '20051128T15:10:00';
+    $cf_date->_CanonicalizeValueDateTime(\%args);
+    is($args{'Content'}, '2005-11-28 15:10:00', "YYYYDDMMThh:mm:ss");
+
+    $args{'Content'} = '2005-11-28 15:10:00';
+    $cf_date->_CanonicalizeValueDateTime(\%args);
+    is($args{'Content'}, '2005-11-28 15:10:00', "YYYY-DD-MM hh:mm:ss");
+}
+
+diag('Test relative dates');
+{
+    my %args;
+    my $cf_date = RT::CustomField->new( RT->SystemUser );
+
+    set_fixed_time("2005-11-28T15:10:00Z");
+    $args{'Content'} = 'now';
+    warning_like {
+        $cf_date->_CanonicalizeValueDateTime(\%args);
+    } qr/as a iso format/, "Couldn't parse as iso";
+
+    is($args{'Content'}, '2005-11-28 15:10:00', "now");
+
+    $args{'Content'} = '1 day ago';
+    warning_like {
+        $cf_date->_CanonicalizeValueDateTime(\%args);
+    } qr/as a iso format/, "Couldn't parse as iso";
+    is($args{'Content'}, '2005-11-27 15:10:00', "1 day ago");
+    restore_time();
+}
+
 
 done_testing;

-----------------------------------------------------------------------


More information about the rt-commit mailing list