Skip to content

Commit 03dd495

Browse files
committed
fix(validator): strict checks for in-step, handle weekends correctly
1 parent d8630b2 commit 03dd495

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Validator.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function inStep(int $value, string $offset): bool
5353
return false;
5454
}
5555

56-
if (\strpos($offset, '*/') !== false || \strpos($offset, '0/') !== false) {
56+
if (\strpos($offset, '*/') === 0 || \strpos($offset, '0/') === 0) {
5757
return $value % $parts[1] === 0;
5858
}
5959

@@ -91,7 +91,7 @@ public function inStepRange(int $value, int $start, int $end, int $step): bool
9191
* @internal
9292
*
9393
* @param string $value
94-
* @param ReferenceTime $time
94+
* @param ReferenceTime $reference
9595
*
9696
* @return bool
9797
*/
@@ -140,7 +140,7 @@ protected function isClosestWeekDay(int $value, string $month, ReferenceTime $re
140140
* @internal
141141
*
142142
* @param string $value
143-
* @param ReferenceTime $time
143+
* @param ReferenceTime $reference
144144
*
145145
* @return bool
146146
*/
@@ -156,16 +156,18 @@ public function isValidWeekDay(string $value, ReferenceTime $reference): bool
156156
$this->unexpectedValue(4, $value);
157157
}
158158

159-
list($day, $nth) = \explode('#', \str_replace('0#', '7#', $value));
159+
list($day, $nth) = \explode('#', \str_replace('7#', '0#', $value));
160160

161-
if (!$this->isNthWeekDay((int) $day, (int) $nth) || $reference->weekDay1() != $day) {
161+
if (!$this->isNthWeekDay((int) $day, (int) $nth) || $reference->weekDay() != $day) {
162162
return false;
163163
}
164164

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

168168
/**
169+
* Throws UnexpectedValueException.
170+
*
169171
* @param int $pos
170172
* @param string $value
171173
*

0 commit comments

Comments
 (0)