From 0d3bb28015cdd17d40f1fb613f58cafea20a81a0 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 5 Nov 2019 14:18:28 +0000 Subject: [PATCH] Bug 25665: (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 Signed-off-by: Victor Grousset/tuxayo --- Koha/Calendar.pm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index 8f9a2a4023..cb062862d9 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -345,17 +345,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