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 <dcook@prosentient.com.au>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Martin Renvoize 2020-03-11 15:59:19 +00:00 committed by Jonathan Druart
parent d8d33c0e1b
commit 1059303f90
1 changed files with 6 additions and 3 deletions

View File

@ -123,7 +123,7 @@ sub dt_from_string {
(?<minute>\d{2})
:
(?<second>\d{2})
(\.\d{1,3})?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))
(\.\d{1,3})?(([Zz])|((?<offset>[\+|\-])(?<hours>[01][0-9]|2[0-3]):(?<minutes>[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;