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 <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Martin Renvoize 2019-10-16 13:10:43 +01:00
parent bbdee010aa
commit a693c7243c
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F

View file

@ -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 {