}
elsif ($cgi->param('hold_suspend') =~ /p/) {
eval {
- my $next_open_time = $e->json_query({
- from => [
- 'evergreen.find_next_open_time',
- $cgi->param('pickup_lib') || $self->ctx->{search_ou},
- DateTime::Format::ISO8601->new()
- ]
- })->[0];
- my $dt = DateTime::Format::ISO8601->parse_datetime($next_open_time);
- $ctx->{thaw_date} = $dt->ymd;
+ #start thaw date at current time
+ my $thaw_dt = DateTime::Format::ISO8601->new();
+ my $thaw_found = 0;
+ my $h = $e->search_actor_hours_of_operation({id => $cgi->param('pickup_lib') || $self->ctx->{search_ou}})->[0];
+ #look for thaw date up to 1 week in future
+ for(my $dow = 0;!$thaw_found && $dow < 6;$dow++){
+ if($dow){
+ # need to check another day
+ # set to first moment of tomorrow
+ $thaw_dt->add(days => 1);
+ $thaw_dt->set(hour => 0,minute => 0, second=> 0);
+ }
+ my $day_of_week = $thaw_dt->wday;
+ my $open_time_st = $h->{'dow_'.$day_of_week.'_open'};
+ my $close_time_st = $h->{'dow_'.$day_of_week.'_close'};
+ # library closed, check back tomorrow
+ next if($open_time_st eq '00:00:00' and $close_time_st eq '00:00:00');
+ my @open_times = split(':',$open_time_st);
+ my @close_times = split(':',$close_time_st);
+ # create open/close datetimes based on current thaw date
+ my $open_time = $thaw_dt->clone->set(hour => @open_times[0],minute => @open_times[1],second => @open_times[2]);
+ my $close_time = $thaw_dt->clone->set(hour => @open_times[0],minute => @open_times[1],second => @open_times[2]);
+ if($thaw_dt->is_between($open_time,$close_time)){
+ # we found a good time, end loop
+ $thaw_found = 1;
+ }
+ else if(DateTime->compare($thaw_dt,$close_time) <= 0){
+ # our thaw date is before opening time
+ # set thaw date to opening time
+ $thaw_found->set(hour => $open_times[0],minute => $open_times[1])
+ $thaw_found = 1;
+ }
+ # thaw date falls after closing time, check tomorrow
+ }
+ $ctx->{thaw_date} = $thaw_dt->ymd;
$ctx->{frozen} = 1;
};
if ($@) {