From 5fbae8fece41cf6aa18b7a5c93ce4ccd41d984de Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 17 Dec 2021 12:36:20 +0000 Subject: [PATCH] Bug 29718: (QA follow-up) Add optional offset handling Content-Type: text/plain; charset=utf-8 ISO8601 optionally supports timezone offsets. If a timezone is ommited, we should assume 'local' time (Which in our case is instance configuration time), if we are passed 'Z' or 'z' we should set timezone to 'UTC', otherwise we should set the timezone to the passed offset. Whilst ISO8601 does NOT support AM/PM, I left that intact as it has historical relevance in Koha and we share the ISO parsing with SQL type parsing amongth other things. Signed-off-by: Martin Renvoize Signed-off-by: Marcel de Rooy --- Koha/DateUtils.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index 57fba31284..0e8bd3c6fc 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -143,7 +143,7 @@ sub dt_from_string { } # Add the faculative time part [hh:mm[:ss]] - my $time_re .= qr| + my $time_re .= qr{ ( [Tt]? \s* @@ -158,8 +158,11 @@ sub dt_from_string { \s (?\w{2}) )? + ( + (?[Zz]$)|((?[\+|\-])(?[01][0-9]|2[0-3]):(?[0-5][0-9])) + )? )? - |xms; + }xms; $regex .= $time_re unless ( $date_format eq 'rfc3339' ); $fallback_re .= $time_re; @@ -175,6 +178,9 @@ sub dt_from_string { second => $+{second}, ); $ampm = $+{ampm}; + if ( $+{utc} ) { + $tz = DateTime::TimeZone->new( name => 'UTC' ); + } if ( $+{offset} ) { # If offset given, set inbound timezone using it. $tz = DateTime::TimeZone->new( name => $+{offset} . $+{hours} . $+{minutes} ); -- 2.20.1