fix issues in API call
authorLlewellyn Marshall <llewellyn.marshall@ncdcr.gov>
Thu, 18 Aug 2022 16:22:41 +0000 (12:22 -0400)
committerLlewellyn Marshall <llewellyn.marshall@ncdcr.gov>
Thu, 18 Aug 2022 16:22:41 +0000 (12:22 -0400)
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm

index acec076..1d8dac3 100644 (file)
@@ -1488,16 +1488,17 @@ __PACKAGE__->register_method(
 sub get_next_operating_hour {
     my( $self, $client, $org_id, $start_time_str ) = @_;
     my $e = new_editor();
+    my $found = 0;
     my $start_time;
        if(defined($start_time_str)){
                $start_time = DateTime::Format::ISO8601->parse_datetime($start_time_str);
        }
        else{
                # default to current time if none defined
-               $start_time = DateTime::Format::ISO8601->new();
+               $start_time = DateTime->now();
        }
-       my $h = $e->search_actor_hours_of_operation({id => $org_id})->[0];
-       my $found = 0;
+       my $h = $e->search_actor_org_unit_hours_of_operation({id => $org_id})->[0];
+    return $e->event unless defined $h;
        # look for thaw date up to 1 week in future 
        for(my $dow = 0;!$found && $dow < 6;$dow++){
                if($dow){
@@ -1505,32 +1506,33 @@ sub get_next_operating_hour {
                        # set to first moment of tomorrow
                        $start_time->add(days => 1);
                        $start_time->set(hour => 0,minute => 0, second=> 0);
-               }
-               my $day_of_week = $start_time->wday;
-               my $open_time_st = $h->{'dow_'.$day_of_week.'_open'};
-               my $close_time_st = $h->{'dow_'.$day_of_week.'_close'};
+               }               
+        my $day_of_week = $start_time->wday;
+               my $open_time_f = 'dow_'.$day_of_week.'_open';
+               my $close_time_f = 'dow_'.$day_of_week.'_close';
+               my $open_time_st = $h->$open_time_f;
+               my $close_time_st = $h->$close_time_f;        
                # 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 = $start_time->clone->set(hour => @open_times[0],minute => @open_times[1],second => @open_times[2]);
-               my $close_time = $start_time->clone->set(hour => @open_times[0],minute => @open_times[1],second => @open_times[2]);
-               if($start_time->is_between($open_time,$close_time)){
+               my $open_time = $start_time->clone->set(hour => $open_times[0],minute => $open_times[1],second => $open_times[2]);
+               my $close_time = $start_time->clone->set(hour => $close_times[0],minute => $close_times[1],second => $close_times[2]);
+               if(DateTime->compare($start_time,$open_time) >= 0 && DateTime->compare($start_time,$close_time) < 0){
                        # we found a good time, end loop
-                       $found = 1;
+                       return $start_time->iso8601;
                }
-               else if(DateTime->compare($thaw_dt,$close_time) <= 0){
+               elsif(DateTime->compare($start_time,$open_time) <= 0){
                        # our start is before opening time
                        # set start to opening time
-                       $start_time->set(hour => $open_times[0],minute => $open_times[1])
-                       $found = 1;
+                       $start_time->set(hour => $open_times[0],minute => $open_times[1]);
+                       return $start_time->iso8601;
                }
                # start falls after closing time, check tomorrow
        }
-       # error, library is never operating
-       return $e->event unless $found;
-       return DateTime::Format::ISO8601->format_datetime($start_time);
+       # error, library must not be operational
+       return $e->event;       
 }
 
 __PACKAGE__->register_method(