From b894e4e910b7103cea923f98ee00369e3f3e671e Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Wed, 20 Oct 2021 14:35:17 +0700 Subject: [PATCH] fix(validator): strict checks for in-step, handle weekends correctly --- src/Validator.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Validator.php b/src/Validator.php index 7fdd4d1..799e477 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -53,7 +53,7 @@ public function inStep(int $value, string $offset): bool return false; } - if (\strpos($offset, '*/') !== false || \strpos($offset, '0/') !== false) { + if (\strpos($offset, '*/') === 0 || \strpos($offset, '0/') === 0) { return $value % $parts[1] === 0; } @@ -91,7 +91,7 @@ public function inStepRange(int $value, int $start, int $end, int $step): bool * @internal * * @param string $value - * @param ReferenceTime $time + * @param ReferenceTime $reference * * @return bool */ @@ -140,7 +140,7 @@ protected function isClosestWeekDay(int $value, string $month, ReferenceTime $re * @internal * * @param string $value - * @param ReferenceTime $time + * @param ReferenceTime $reference * * @return bool */ @@ -156,9 +156,9 @@ public function isValidWeekDay(string $value, ReferenceTime $reference): bool $this->unexpectedValue(4, $value); } - list($day, $nth) = \explode('#', \str_replace('0#', '7#', $value)); + list($day, $nth) = \explode('#', \str_replace('7#', '0#', $value)); - if (!$this->isNthWeekDay((int) $day, (int) $nth) || $reference->weekDay1() != $day) { + if (!$this->isNthWeekDay((int) $day, (int) $nth) || $reference->weekDay() != $day) { return false; } @@ -166,6 +166,8 @@ public function isValidWeekDay(string $value, ReferenceTime $reference): bool } /** + * Throws UnexpectedValueException. + * * @param int $pos * @param string $value *