diff --git a/src/Expression.php b/src/Expression.php index 3941657..812b1d8 100644 --- a/src/Expression.php +++ b/src/Expression.php @@ -88,7 +88,7 @@ public static function isDue($expr, $time = null) */ public function isCronDue($expr, $time = null) { - list($expr, $time) = $this->process($expr, $time); + list($expr, $times) = $this->process($expr, $time); $checker = new SegmentChecker; foreach ($expr as $pos => $segment) { @@ -96,7 +96,7 @@ public function isCronDue($expr, $time = null) continue; } - if (!$checker->checkDue($segment, $pos, $time)) { + if (!$checker->checkDue($segment, $pos, $times)) { return false; } } @@ -127,11 +127,10 @@ protected function process($expr, $time) ); } - $time = static::normalizeTime($time); + $time = static::normalizeTime($time); + $times = \array_map('intval', \explode(' ', \date('i G j n w Y t d m N', $time))); - $time = \array_map('intval', \explode(' ', \date('i G j n w Y t d m N', $time))); - - return [$expr, $time]; + return [$expr, $times]; } protected function normalizeTime($time) diff --git a/src/SegmentChecker.php b/src/SegmentChecker.php index 59d0e0d..5b152a2 100644 --- a/src/SegmentChecker.php +++ b/src/SegmentChecker.php @@ -33,17 +33,17 @@ public function __construct() * * @param string $segment * @param int $pos - * @param int $time + * @param array $times * * @return bool */ - public function checkDue($segment, $pos, $time) + public function checkDue($segment, $pos, $times) { $isDue = true; $offsets = \explode(',', \trim($segment)); foreach ($offsets as $offset) { - if (null === $isDue = $this->isOffsetDue($offset, $pos, $time)) { + if (null === $isDue = $this->isOffsetDue($offset, $pos, $times)) { throw new \UnexpectedValueException( sprintf('Invalid offset value at segment #%d: %s', $pos, $offset) ); @@ -62,37 +62,37 @@ public function checkDue($segment, $pos, $time) * * @param string $offset * @param int $pos - * @param array $time + * @param array $times * * @return bool|null */ - protected function isOffsetDue($offset, $pos, $time) + protected function isOffsetDue($offset, $pos, $times) { if (\strpos($offset, '/') !== false) { - return $this->validator->inStep($time[$pos], $offset); + return $this->validator->inStep($times[$pos], $offset); } if (\strpos($offset, '-') !== false) { - return $this->validator->inRange($time[$pos], $offset); + return $this->validator->inRange($times[$pos], $offset); } if (\is_numeric($offset)) { - return $time[$pos] == $offset; + return $times[$pos] == $offset; } - return $this->checkModifier($offset, $pos, $time); + return $this->checkModifier($offset, $pos, $times); } - protected function checkModifier($offset, $pos, $time) + protected function checkModifier($offset, $pos, $times) { $isModifier = \strpbrk($offset, 'LCW#'); if ($pos === 2 && $isModifier) { - return $this->validator->isValidMonthDay($offset, $time); + return $this->validator->isValidMonthDay($offset, $times); } if ($pos === 4 && $isModifier) { - return $this->validator->isValidWeekDay($offset, $time); + return $this->validator->isValidWeekDay($offset, $times); } return null;