X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=Koha%2FCalendar.pm;h=75c5c9ebb15c6516692a323f483134c30a4f2bf7;hb=32c5ef613d8805304c1b7f97e597116226b7bbe8;hp=1e7299c083ce8440fa386bbcd22281baf51af3cd;hpb=b915f4ff322b4639ad1b8705f7d11977b8c487e4;p=koha.git diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index 1e7299c083..75c5c9ebb1 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -168,11 +168,9 @@ sub days_between { my $self = shift; my $start_dt = shift; my $end_dt = shift; - $start_dt->truncate( to => 'hours' ); - $end_dt->truncate( to => 'hours' ); # start and end should not be closed days - my $duration = $end_dt - $start_dt; + my $duration = $end_dt->delta_days($start_dt); $start_dt->truncate( to => 'days' ); $end_dt->truncate( to => 'days' ); while ( DateTime->compare( $start_dt, $end_dt ) == -1 ) { @@ -185,6 +183,25 @@ sub days_between { } +sub hours_between { + my ($self, $start_dt, $end_dt) = @_; + my $duration = $end_dt->delta_ms($start_dt); + $start_dt->truncate( to => 'days' ); + $end_dt->truncate( to => 'days' ); + # NB this is a kludge in that it assumes all days are 24 hours + # 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 + while ( DateTime->compare( $start_dt, $end_dt ) == -1 ) { + $start_dt->add( days => 1 ); + if ( $self->is_holiday($start_dt) ) { + $duration->subtract( hours => 24 ); + } + } + return $duration; + +} + sub _mockinit { my $self = shift; $self->{weekly_closed_days} = [ 1, 0, 0, 0, 0, 0, 0 ]; # Sunday only