From: Bill Erickson Date: Wed, 29 Oct 2014 21:09:55 +0000 (-0400) Subject: KMAIN-908: Hold Shelf Time Calculation X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=fc9901ff3b1374d27f610f4912741e227b7c2128;p=working%2FEvergreen.git KMAIN-908: Hold Shelf Time Calculation Cross-port: 8cb3172 --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm index 0a1d023a80..3808a3244d 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm @@ -1112,41 +1112,37 @@ sub set_hold_shelf_expire_time { $editor ); - return undef unless $shelf_expire; + #Grab the numeric interval from the text + my $interval; + if ( $shelf_expire =~ /(\d+)/g) { + $interval = $1; + } + + return undef unless $shelf_expire and $interval; $start_time = ($start_time) ? DateTime::Format::ISO8601->new->parse_datetime(clean_ISO8601($start_time)) : DateTime->now(time_zone => 'local'); # without time_zone we get UTC ... yuck! - my $seconds = OpenILS::Utils::DateTime->interval_to_seconds($shelf_expire); - my $expire_time = $start_time->add(seconds => $seconds); - - # if the shelf expire time overlaps with a pickup lib's - # closed date, push it out to the first open date - my $dateinfo = $U->storagereq( - 'open-ils.storage.actor.org_unit.closed_date.overlap', - $hold->pickup_lib, $expire_time->strftime('%FT%T%z')); - - if($dateinfo) { - my $dt_parser = DateTime::Format::ISO8601->new; - $expire_time = $dt_parser->parse_datetime(clean_ISO8601($dateinfo->{end})); - - # TODO: enable/disable time bump via setting? - $expire_time->set(hour => '23', minute => '59', second => '59'); - - $logger->info("circulator: shelf_expire_time overlaps". - " with closed date, pushing expire time to $expire_time"); + my $interval_counter = 0; + my $expire_time = $start_time; + my $dt_parser = DateTime::Format::ISO8601->new; + + # We are going to walk through each day from today up to the interval days + # And keep adding a day as long as a closed day is encountered, so that the + # interval will be made up of only open days + while ( $interval_counter != $interval) { + $expire_time = $expire_time->add(days => 1 ); + my $dateinfo = $U->storagereq( + 'open-ils.storage.actor.org_unit.closed_date.overlap', + $hold->pickup_lib, $expire_time->strftime('%FT%T%z')); + if($dateinfo) { + $expire_time = $dt_parser->parse_datetime(clean_ISO8601($dateinfo->{end})); + } + $interval_counter++; } - $expire_time->truncate( to => 'day'); - $expire_time->add(days => 1); - my $temp_expire_time = $expire_time->clone(); - $temp_expire_time->set_time_zone($tz); - if($temp_expire_time->is_dst()) { - $expire_time->set(hour => '06', minute => '59', second => '00'); - } else { - $expire_time->set(hour => '07', minute => '59', second => '00'); - } + $expire_time->set(hour => '23', minute => '59', second => '59'); $hold->shelf_expire_time($expire_time->strftime('%FT%T%z')); return undef; }