@@ 216-239 (lines=24) @@ | ||
213 | * Notice: This will return DateTimeInterface on next major release |
|
214 | * https://github.com/spatie/opening-hours/pull/75 |
|
215 | */ |
|
216 | public function nextOpen(DateTimeInterface $dateTime): DateTime |
|
217 | { |
|
218 | if (! ($dateTime instanceof DateTimeImmutable)) { |
|
219 | $dateTime = clone $dateTime; |
|
220 | } |
|
221 | ||
222 | $openingHoursForDay = $this->forDate($dateTime); |
|
223 | $nextOpen = $openingHoursForDay->nextOpen(Time::fromDateTime($dateTime)); |
|
224 | ||
225 | while ($nextOpen === false) { |
|
226 | $dateTime = $dateTime |
|
227 | ->modify('+1 day') |
|
228 | ->setTime(0, 0, 0); |
|
229 | ||
230 | $openingHoursForDay = $this->forDate($dateTime); |
|
231 | ||
232 | $nextOpen = $openingHoursForDay->nextOpen(Time::fromDateTime($dateTime)); |
|
233 | } |
|
234 | ||
235 | $nextDateTime = $nextOpen->toDateTime(); |
|
236 | $dateTime = $dateTime->setTime($nextDateTime->format('G'), $nextDateTime->format('i'), 0); |
|
237 | ||
238 | return $dateTime; |
|
239 | } |
|
240 | ||
241 | /** |
|
242 | * Returns the next closed time. |
|
@@ 247-270 (lines=24) @@ | ||
244 | * Notice: This will return DateTimeInterface on next major release |
|
245 | * https://github.com/spatie/opening-hours/pull/75 |
|
246 | */ |
|
247 | public function nextClose(DateTimeInterface $dateTime): DateTime |
|
248 | { |
|
249 | if (! ($dateTime instanceof DateTimeImmutable)) { |
|
250 | $dateTime = clone $dateTime; |
|
251 | } |
|
252 | ||
253 | $openingHoursForDay = $this->forDate($dateTime); |
|
254 | $nextClose = $openingHoursForDay->nextClose(Time::fromDateTime($dateTime)); |
|
255 | ||
256 | while ($nextClose === false) { |
|
257 | $dateTime = $dateTime |
|
258 | ->modify('+1 day') |
|
259 | ->setTime(0, 0, 0); |
|
260 | ||
261 | $openingHoursForDay = $this->forDate($dateTime); |
|
262 | ||
263 | $nextClose = $openingHoursForDay->nextClose(Time::fromDateTime($dateTime)); |
|
264 | } |
|
265 | ||
266 | $nextDateTime = $nextClose->toDateTime(); |
|
267 | $dateTime = $dateTime->setTime($nextDateTime->format('G'), $nextDateTime->format('i'), 0); |
|
268 | ||
269 | return $dateTime; |
|
270 | } |
|
271 | ||
272 | public function regularClosingDays(): array |
|
273 | { |