From 622d4f713be7d3984443f4c5d3a25fd88671fa82 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 e115c57d76..e56c39ddd5 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -366,17 +366,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.39.5