+sub days_between {
+ my $self = shift;
+ my $start_dt = shift;
+ my $end_dt = shift;
+
+ my $datestart_temp = $start_dt->clone();
+ my $dateend_temp = $end_dt->clone();
+
+ # start and end should not be closed days
+ my $duration = $dateend_temp->delta_days($datestart_temp);
+ $datestart_temp->truncate( to => 'days' );
+ $dateend_temp->truncate( to => 'days' );
+ while ( DateTime->compare( $datestart_temp, $dateend_temp ) == -1 ) {
+ $datestart_temp->add( days => 1 );
+ if ( $self->is_holiday($datestart_temp) ) {
+ $duration->subtract( days => 1 );
+ }
+ }
+ return $duration;
+
+}
+
+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
+ $self->{day_month_closed_days} = { 6 => { 16 => 1, } };
+ my $dates = [];
+ $self->{exception_holidays} =
+ DateTime::Set->from_datetimes( dates => $dates );
+ my $special = DateTime->new(
+ year => 2011,
+ month => 6,
+ day => 1,
+ time_zone => 'Europe/London',
+ );
+ push @{$dates}, $special;
+ $self->{single_holidays} = DateTime::Set->from_datetimes( dates => $dates );
+ $self->{days_mode} = 'Calendar';
+ return;
+}
+