From 1059303f90eaedbca76f3491a2b6b008a77abdc5 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 11 Mar 2020 15:59:19 +0000 Subject: [PATCH] Bug 24850: Correct offset handling in dt_from_string This patch adds correct handling for when an offset is passed within an RFC3339 formatted datetime. Test plan 1/ Run the DateUtils test and varify it now passes. Signed-off-by: David Cook Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- Koha/DateUtils.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index f5becf0405..fb1d0fa6d5 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -123,7 +123,7 @@ sub dt_from_string { (?\d{2}) : (?\d{2}) - (\.\d{1,3})?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9])) + (\.\d{1,3})?(([Zz])|((?[\+|\-])(?[01][0-9]|2[0-3]):(?[0-5][0-9]))) /xms; } elsif ( $date_format eq 'iso' or $date_format eq 'sql' ) { @@ -166,6 +166,9 @@ sub dt_from_string { second => $+{second}, ); $ampm = $+{ampm}; + if ( $+{offset} ) { + $tz = DateTime::TimeZone->new( name => $+{offset} . $+{hours} . $+{minutes} ); + } } elsif ( $date_string =~ $fallback_re ) { %dt_params = ( year => $+{year}, @@ -202,7 +205,7 @@ sub dt_from_string { DateTime->new( %dt_params, # No TZ for dates 'infinite' => see bug 13242 - ( $dt_params{year} < 9999 ? ( time_zone => $tz->name ) : () ), + ( $dt_params{year} < 9999 ? ( time_zone => $tz ) : () ), ); }; if ($@) { @@ -210,7 +213,7 @@ sub dt_from_string { $dt = DateTime->new( %dt_params, # No TZ for dates 'infinite' => see bug 13242 - ( $dt_params{year} < 9999 ? ( time_zone => $tz->name ) : () ), + ( $dt_params{year} < 9999 ? ( time_zone => $tz ) : () ), ); } return $dt; -- 2.39.5