From 1b8de3d8f04b5902d2c2852cd6d809d0a93b560c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 26 Mar 2020 11:12:26 +0000 Subject: [PATCH] Bug 24850: Continue to handle default time and daylight saving This patch prevents the call to set_time_zone if we are handling a dateonly datetime string or a DST time Signed-off-by: David Cook Signed-off-by: Marcel de Rooy --- Koha/DateUtils.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index 434ce6e53e..11952bc78d 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -194,6 +194,9 @@ sub dt_from_string { $dt_params{day} = '01' if $dt_params{day} eq '00'; # Set default hh:mm:ss to 00:00:00 + my $date_only = ( !defined( $dt_params{hour} ) + && !defined( $dt_params{minute} ) + && !defined( $dt_params{second} ) ); $dt_params{hour} = 00 unless defined $dt_params{hour}; $dt_params{minute} = 00 unless defined $dt_params{minute}; $dt_params{second} = 00 unless defined $dt_params{second}; @@ -207,6 +210,7 @@ sub dt_from_string { } } + my $floating = 0; my $dt = eval { DateTime->new( %dt_params, @@ -216,13 +220,17 @@ sub dt_from_string { }; if ($@) { $tz = DateTime::TimeZone->new( name => 'floating' ); + $floating = 1; $dt = DateTime->new( %dt_params, # No TZ for dates 'infinite' => see bug 13242 ( $dt_params{year} < 9999 ? ( time_zone => $tz ) : () ), ); } - $dt->set_time_zone($server_tz); + + # Convert to configured timezone (unless we started with a dateonly string or had to drop to floating time) + $dt->set_time_zone($server_tz) unless ( $date_only || $floating ); + return $dt; } -- 2.20.1