From c6a146ed32c81db78a2010db474a6458e6e4f58c 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 Content-Type: text/plain; charset=utf-8 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 958cd5f3bb..09186242ab 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -188,6 +188,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}; @@ -201,6 +204,7 @@ sub dt_from_string { } } + my $floating = 0; my $dt = eval { DateTime->new( %dt_params, @@ -210,13 +214,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.11.0