From 8017463d34bfc37841a62f9771c80aeebf5376b2 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 flawed, 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. Sponsored-by: PTFS Europe Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- C4/Circulation.pm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index f4bf52c8dd..8fa89866e6 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3893,11 +3893,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.39.5