From cb4bbdda5d6cbb634d92fee2c09c52097943a8b6 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 16 Oct 2019 13:10:43 +0100 Subject: [PATCH] Bug 23382: hours_between should match the logic of days_between The loops for subtraction holiday dates in hours_between and days_between differed and as such their handling of start and end boundaries for days also differed. This patch makes them handle the boundary days consistently. Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize (cherry picked from commit a693c7243c23f888e2fad38a4fff9f37ff4a9301) Signed-off-by: Lucas Gass --- Koha/Calendar.pm | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index fc63572b28..07faad58dd 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -344,21 +344,17 @@ sub hours_between { # However for hourly loans the logic should be expanded to # take into account open/close times then it would be a duration # of library open hours + # start and end should not be closed days my $skipped_days = 0; - for (my $dt = $start_dt->clone(); - $dt <= $end_dt; - $dt->add(days => 1) - ) { - if ($self->is_holiday($dt)) { - ++$skipped_days; - } + while( $start_dt->compare($end_dt) < 1 ) { + $start_dt->add( days => 1 ); + $skipped_days++ if $self->is_holiday($start_dt); } if ($skipped_days) { $duration->subtract_duration(DateTime::Duration->new( hours => 24 * $skipped_days)); } return $duration; - } sub set_daysmode { -- 2.39.5