From de1697c87779d1624baa8eae19eb24c71a43ac74 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 5 Nov 2019 14:18:28 +0000 Subject: [PATCH] Bug 23382: (RM follow-up) Revert "hours_between should match..." This reverts commit a693c7243c23f888e2fad38a4fff9f37ff4a9301 which caused regressions. The original loop compared start date to end date and iterated all the way to start date equals end date. The alternate implimentation inadvertantly looped from start date, skipped the first day then iterated up to one day beyond end date. Signed-off-by: Martin Renvoize --- Koha/Calendar.pm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index 07faad58dd..fc63572b28 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -344,17 +344,21 @@ 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; - while( $start_dt->compare($end_dt) < 1 ) { - $start_dt->add( days => 1 ); - $skipped_days++ if $self->is_holiday($start_dt); + for (my $dt = $start_dt->clone(); + $dt <= $end_dt; + $dt->add(days => 1) + ) { + if ($self->is_holiday($dt)) { + ++$skipped_days; + } } if ($skipped_days) { $duration->subtract_duration(DateTime::Duration->new( hours => 24 * $skipped_days)); } return $duration; + } sub set_daysmode { -- 2.20.1