From 4ff54a981aec67663c030a80a47c8fc42bf690fe Mon Sep 17 00:00:00 2001 From: Hayley Pelham Date: Thu, 28 Apr 2022 23:43:52 +0000 Subject: [PATCH] Bug 6796: (follow-up) Fix logic for calculating following day's open hours Since days for branch hours are stored as 0-6 in the database, when it's a Saturday (6) incrementing the date leads to an error when issuing an hourly loan because no opening hours are found for the non-existent day (7). This patch fixes this by calculating the tomorrow day and setting it to 0 if it's greater than 6. This patch also corrects the mappings for days, where local_day_of_week caluclates the date with Sunday first, which put it out of sync with the database opening hours days. Sponsored-by: Auckland University of Technology Sponsored-by: Catalyst IT --- C4/Circulation.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 92351b75d4c..1915bf1fed7 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3826,10 +3826,13 @@ 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->local_day_of_week - 1; + my $dayofweek = $datedue->day_of_week - 1; + my $tomorrow_dayofweek = $dayofweek + 1; + # 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({ branchcode => $branch, day => $dayofweek }); my @close = undef; - my $tomorrowhours = Koha::Library::Hours->find({ branchcode => $branch, day => $dayofweek+1 }); # get open hours of next day + my $tomorrowhours = Koha::Library::Hours->find({ branchcode => $branch, day => $tomorrow_dayofweek }); # get open hours of next day my @open = undef; if ( $todayhours->close_time and $tomorrowhours->open_time ) { @close = split( ":", $todayhours->close_time ); -- 2.30.2