From d6cbe93352b52881ec4c1708eafdd4ba836380fe 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. --- 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.20.1