From 013a5485ad79ba2204e5220a28d040c285063998 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: Agustin Moyano --- Koha/DateUtils.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index e7923fcca5..4c92d1d88c 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -181,10 +181,14 @@ 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}; + my $floating = 0; my $dt = eval { DateTime->new( %dt_params, @@ -194,13 +198,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.25.0