/**
  *
  * @param tx_caretaker_TestNode $node
  * @param tx_caretaker_NodeResult $latestTestResult
  * @param array $options
  * @return boolean
  */
 protected function shouldReturnLatestResult($node, $latestTestResult, $options)
 {
     $forceUpdate = isset($options['forceUpdate']) && $options['forceUpdate'] === TRUE;
     $returnLatestResult = FALSE;
     if (!$forceUpdate) {
         if ($latestTestResult) {
             // test is not in due state so retry
             switch ($latestTestResult->getState()) {
                 case tx_caretaker_Constants::state_due:
                     $returnLatestResult = FALSE;
                     break;
                 case tx_caretaker_Constants::state_ack:
                     $returnLatestResult = TRUE;
                     break;
                 case tx_caretaker_Constants::state_ok:
                     if ($latestTestResult->getTimestamp() > time() - $node->getTestInterval()) {
                         $returnLatestResult = TRUE;
                     }
                     break;
                 case tx_caretaker_Constants::state_undefined:
                 case tx_caretaker_Constants::state_warning:
                 case tx_caretaker_Constants::state_error:
                     // if due mode is 1 than retry
                     if ($node->getTestDue() == 1) {
                         $returnLatestResult = FALSE;
                     } else {
                         if ($latestTestResult->getTimestamp() > time() - $node->getTestInterval()) {
                             $returnLatestResult = TRUE;
                         }
                     }
                     break;
             }
         }
         // test should not run this hour
         if (!$returnLatestResult && ($node->getStartHour() > 0 || $node->getStopHour() > 0)) {
             $localTime = localtime(time(), TRUE);
             $localHour = $localTime['tm_hour'];
             if ($localHour < $node->getStartHour() || $localHour >= $node->getStopHour()) {
                 $returnLatestResult = TRUE;
             }
         }
     }
     return $returnLatestResult;
 }
 /**
  * Add a Result to Range
  *
  * @param tx_caretaker_NodeResult $result
  */
 public function addResult($result)
 {
     $ts = (int) $result->getTimestamp();
     $this->array[$ts] = $result;
     if ($ts < $this->last_timestamp) {
         ksort($this->array);
     } else {
         $this->last_timestamp = $ts;
     }
     if ($this->start_timestamp !== NULL && $ts < $this->start_timestamp) {
         $this->start_timestamp = $ts;
     }
     if ($this->end_timestamp !== NULL && $ts > $this->end_timestamp) {
         $this->end_timestamp = $ts;
     }
 }