Mailing List Archive

rt branch, 4.4-trunk, updated. rt-4.4.4-347-gf6ce56f0bf
The branch, 4.4-trunk has been updated
via f6ce56f0bf61a9f5b4222935f015238be6042486 (commit)
via acfd5c9bebc61be9dea831d2effa656742913114 (commit)
from 25d25be0dfe58855404ac707d4815d43e1af6680 (commit)

Summary of changes:
lib/RT/Date.pm | 13 +++++++++----
t/api/date.t | 12 ++++++++++++
2 files changed, 21 insertions(+), 4 deletions(-)

- Log -----------------------------------------------------------------
commit acfd5c9bebc61be9dea831d2effa656742913114
Author: Dianne Skoll <dianne@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..12ef573614 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -171,10 +171,15 @@ 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..19a0a01532 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-MMThh:mm:ss");
+
+ $date->Set(Format => 'ISO', Value => '2005-11-28T15:10:00Z');
+ is($date->ISO, '2005-11-28 15:10:00', "YYYY-DD-MMThh:mm:ssZ");
+
$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");

@@ -304,6 +310,12 @@ my $year = (localtime(time))[5] + 1900;
$date->Set(Format => 'ISO', Value => '20051128151000');
is($date->ISO, '2005-11-28 15:10:00', "YYYYDDMMhhmmss");

+ $date->Set(Format => 'ISO', Value => '20051128T151000');
+ is($date->ISO, '2005-11-28 15:10:00', "YYYYDDMMThhmmss");
+
+ $date->Set(Format => 'ISO', Value => '20051128T151000Z');
+ is($date->ISO, '2005-11-28 15:10:00', "YYYYDDMMThhmmssZ");
+
$date->Set(Format => 'ISO', Value => '1128151000');
is($date->ISO, $year .'-11-28 15:10:00', "DDMMhhmmss");


commit f6ce56f0bf61a9f5b4222935f015238be6042486
Merge: 25d25be0df acfd5c9beb
Author: sunnavy <sunnavy@bestpractical.com>
Date: Sat Apr 17 02:17:54 2021 +0800

Merge branch '4.4/improved-parsing-of-iso-8601-dates' into 4.4-trunk


-----------------------------------------------------------------------
_______________________________________________
rt-commit mailing list
rt-commit@lists.bestpractical.com
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-commit