/**
  * Check if a value is within the specified range.
  * @param $rangeStr string the range (e.g., 0, 1-5, *, etc.)
  * @param $currentValue int value to check if its in the range
  * @param $lastTimestamp int the last time the task was executed
  * @param $timeCompareStr string value to use in strtotime("-X $timeCompareStr")
  * @param $cutoffTimestamp int value will be considered valid if older than this
  * @return boolean
  */
 function _isInRange($rangeStr, $currentValue, $lastTimestamp, $timeCompareStr, $cutoffTimestamp)
 {
     $isValid = false;
     $rangeArray = explode(',', $rangeStr);
     if ($cutoffTimestamp > $lastTimestamp) {
         // Execute immediately if the cutoff time period has past since the task was last run
         $isValid = true;
     }
     for ($i = 0, $count = count($rangeArray); !$isValid && $i < $count; $i++) {
         if ($rangeArray[$i] == '*') {
             // Is wildcard
             $isValid = true;
         }
         if (is_numeric($rangeArray[$i])) {
             // Is just a value
             $isValid = $currentValue == (int) $rangeArray[$i];
         } else {
             if (preg_match('/^(\\d*)\\-(\\d*)$/', $rangeArray[$i], $matches)) {
                 // Is a range
                 $isValid = ScheduledTaskHelper::_isInNumericRange($currentValue, (int) $matches[1], (int) $matches[2]);
             } else {
                 if (preg_match('/^(.+)\\/(\\d+)$/', $rangeArray[$i], $matches)) {
                     // Is a range with a skip factor
                     $skipRangeStr = $matches[1];
                     $skipFactor = (int) $matches[2];
                     if ($skipRangeStr == '*') {
                         $isValid = true;
                     } else {
                         if (preg_match('/^(\\d*)\\-(\\d*)$/', $skipRangeStr, $matches)) {
                             $isValid = ScheduledTaskHelper::_isInNumericRange($currentValue, (int) $matches[1], (int) $matches[2]);
                         }
                     }
                     if ($isValid) {
                         // Check against skip factor
                         $isValid = strtotime("-{$skipFactor} {$timeCompareStr}") > $lastTimestamp;
                     }
                 }
             }
         }
     }
     return $isValid;
 }