From 4c8a93cf65640f074b3206acd5a59116ee7d9e5c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 12 Feb 2024 15:48:06 +0000 Subject: [PATCH] Bug 6796: day_of_week representation fix The code here was floored, DateTime returns a 1-7 indexed array with the first day being Monday, Koha expects an 0-6 indexed array with the first day being Sunday. --- C4/Circulation.pm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 6805bee2a61..23de0b1c890 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3897,11 +3897,20 @@ sub CalcDateDue { # starter vars so don't do calculations directly to $datedue my $potential_datedue = $datedue->clone; my $library_close = $datedue->clone; - my $dayofweek = $datedue->day_of_week - 1; + my $dayofweek = $datedue->day_of_week; + + # Representation fix + # DateTime object dow (1-7) where Monday is 1 + # Arrays are 0-based where 0 = Sunday, not 7. + if ( $dayofweek == 7 ) { + $dayofweek = 0; + } + my $tomorrow_dayofweek = $dayofweek + 1; + if ( $tomorrow_dayofweek == 7 ) { + $tomorrow_dayofweek = 0; + } - # If it's Sunday and tomorrow would be == 7, make tomorrow 0 (Days are stored as 0-6) - if ( $tomorrow_dayofweek > 6 ) { $tomorrow_dayofweek = 0; } my $todayhours = Koha::Library::Hours->find( { library_id => $branch, day => $dayofweek } ); my @close = undef; my $tomorrowhours = Koha::Library::Hours->find( { library_id => $branch, day => $tomorrow_dayofweek } ) -- 2.43.0