[Rt-commit] rt branch, 4.4/improved-parsing-of-iso-8601-dates, repushed
Dianne Skoll
dianne at bestpractical.com
Thu Oct 1 17:03:15 EDT 2020
The branch 4.4/improved-parsing-of-iso-8601-dates was deleted and repushed:
was 1965cb2140032cce5d7ac73ac5e34e00c276beec
now 071ca54e3e7aceca0e5cede39b361c67027a7dfd
1: 1965cb2140 ! 1: 071ca54e3e Tweak RT::Date to parse ISO-8601 combined date and time representations.
@@ -6,21 +6,40 @@
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
+
+ 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
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@
+ if ( $format eq 'unix' ) {
+ return $self->Unix( $args{'Value'} );
}
- elsif (
- ($format eq 'sql' || $format eq 'iso')
+- 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?$/
- ) {
+- ) {
++ 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
--- a/t/api/date.t
More information about the rt-commit
mailing list