Extend hold shelf expire date beyond closed dates
authorBill Erickson <berick@esilibrary.com>
Wed, 8 Jun 2011 19:44:37 +0000 (15:44 -0400)
committerJason Etheridge <jason@esilibrary.com>
Wed, 8 Jun 2011 20:38:56 +0000 (16:38 -0400)
If the shelf_expire_time on a hold would land on a closed date for the
pickup library, push the expire time out to just beyond the close date
range, similar to the circulation due date overlap logic.

In the current iteration, the time component of the date is pushed out
to the end of the day (23:59:59).  If this is not generally the desired
behavior, an org setting could be added to bypass this step so that the
time matches "now" (i.e. capture time) instead.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm

index 02eebd5..1479c1f 100644 (file)
@@ -2913,12 +2913,29 @@ sub put_hold_on_shelf {
     my $shelf_expire = $U->ou_ancestor_setting_value(
         $self->circ_lib, 'circ.holds.default_shelf_expire_interval', $self->editor);
 
-    if($shelf_expire) {
-        my $seconds = OpenSRF::Utils->interval_to_seconds($shelf_expire);
-        my $expire_time = DateTime->now->add(seconds => $seconds);
-        $hold->shelf_expire_time($expire_time->strftime('%FT%T%z'));
+    return undef unless $shelf_expire;
+
+    my $seconds = OpenSRF::Utils->interval_to_seconds($shelf_expire);
+    my $expire_time = DateTime->now->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);
+
+    if($dateinfo) {
+        my $dt_parser = DateTime::Format::ISO8601->new;
+        $expire_time = $dt_parser->parse_datetime(cleanse_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");
     }
 
+    $hold->shelf_expire_time($expire_time->strftime('%FT%T%z'));
     return undef;
 }