Lines 347-380
sub days_between {
Link Here
|
347 |
} |
347 |
} |
348 |
|
348 |
|
349 |
# start and end should not be closed days |
349 |
# start and end should not be closed days |
350 |
my $days = $start_dt->delta_days($end_dt)->delta_days; |
350 |
my $delta_days = $start_dt->delta_days($end_dt)->delta_days; |
351 |
while( $start_dt->compare($end_dt) < 1 ) { |
351 |
while( $start_dt->compare($end_dt) < 1 ) { |
352 |
$days-- if $self->is_holiday($start_dt); |
352 |
$delta_days-- if $self->is_holiday($start_dt); |
353 |
$start_dt->add( days => 1 ); |
353 |
$start_dt->add( days => 1 ); |
354 |
} |
354 |
} |
355 |
return DateTime::Duration->new( days => $days ); |
355 |
return DateTime::Duration->new( days => $delta_days ); |
356 |
} |
356 |
} |
357 |
|
357 |
|
358 |
sub hours_between { |
358 |
sub hours_between { |
359 |
my ($self, $start_date, $end_date) = @_; |
359 |
my ($self, $start_date, $end_date) = @_; |
360 |
my $start_dt = $start_date->clone()->set_time_zone('floating'); |
360 |
my $start_dt = $start_date->clone()->set_time_zone('floating'); |
361 |
my $end_dt = $end_date->clone()->set_time_zone('floating'); |
361 |
my $end_dt = $end_date->clone()->set_time_zone('floating'); |
|
|
362 |
|
362 |
my $duration = $end_dt->delta_ms($start_dt); |
363 |
my $duration = $end_dt->delta_ms($start_dt); |
363 |
$start_dt->truncate( to => 'day' ); |
364 |
$start_dt->truncate( to => 'day' ); |
364 |
$end_dt->truncate( to => 'day' ); |
365 |
$end_dt->truncate( to => 'day' ); |
|
|
366 |
|
365 |
# NB this is a kludge in that it assumes all days are 24 hours |
367 |
# NB this is a kludge in that it assumes all days are 24 hours |
366 |
# However for hourly loans the logic should be expanded to |
368 |
# However for hourly loans the logic should be expanded to |
367 |
# take into account open/close times then it would be a duration |
369 |
# take into account open/close times then it would be a duration |
368 |
# of library open hours |
370 |
# of library open hours |
369 |
my $skipped_days = 0; |
371 |
my $skipped_days = 0; |
370 |
for (my $dt = $start_dt->clone(); |
372 |
while( $start_dt->compare($end_dt) < 1 ) { |
371 |
$dt <= $end_dt; |
373 |
$skipped_days++ if $self->is_holiday($start_dt); |
372 |
$dt->add(days => 1) |
374 |
$start_dt->add( days => 1 ); |
373 |
) { |
|
|
374 |
if ($self->is_holiday($dt)) { |
375 |
++$skipped_days; |
376 |
} |
377 |
} |
375 |
} |
|
|
376 |
|
378 |
if ($skipped_days) { |
377 |
if ($skipped_days) { |
379 |
$duration->subtract_duration(DateTime::Duration->new( hours => 24 * $skipped_days)); |
378 |
$duration->subtract_duration(DateTime::Duration->new( hours => 24 * $skipped_days)); |
380 |
} |
379 |
} |
381 |
- |
|
|