Skip to content

Commit

Permalink
fix(validator): strict checks for in-step, handle weekends correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Oct 20, 2021
1 parent e6c11df commit b894e4e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand All @@ -156,16 +156,18 @@ 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;
}

return \intval($reference->day() / 7) == $nth - 1;
}

/**
* Throws UnexpectedValueException.
*
* @param int $pos
* @param string $value
*
Expand Down

0 comments on commit b894e4e

Please sign in to comment.