From: Bill Erickson Date: Wed, 26 Dec 2018 20:35:18 +0000 (-0500) Subject: JBAS-2166 Org open date range HOO calculation fix X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d58456c4927ab4ff878961278fec42ca9957408b;p=working%2FEvergreen.git JBAS-2166 Org open date range HOO calculation fix When calculating open day ranges, be sure a date selected to avoid an hours of operation collision is not a closed date. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index deed9a9e2b..053f2e1524 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -2518,9 +2518,9 @@ sub org_next_open_day { # Look for the next open hours-of-operation day. If no open day is # found after 7 attempts, give up to avoid looping on orgs that # have no open hours of operation. - my $counter = 0; + my $hoo_counter = 0; my $hoo_date = $end->clone; - while ($counter++ < 7) { + while ($hoo_counter++ < 7) { if (org_operates_on_date($org_id, $hoo_date, $hoo)) { $end = $hoo_date; last; @@ -2528,10 +2528,31 @@ sub org_next_open_day { $hoo_date->add(days => 1); } + if ($hoo_counter == 7) { + # The org unit is closed every day, which means this + # function can never return a meaningful value. + $logger->warn("Org unit $org_id is closed every day"); + return undef; + } + my $start = $begin->strftime('%FT%T%z'); my $stop = $end->strftime('%FT%T%z'); + # If the start and end date match, no date modifications were + # required. Selected date is open. return undef if ($start eq $stop); + + if ($hoo_counter > 1) { + # End date pushed ahead due to an hours of operation collision. + # Confirm the new date is not a closed date. + + my $final_date = org_next_open_day( + $org_id, $stop, $closure_spanset, $hoo); + + # date was bumped ahead even further. + return $final_date if $final_date; + } + return $stop; }