-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #73 and support immutable dates #75
Changes from 2 commits
06df2e0
8728cc0
a6ab623
2539468
6ef4843
4d09a53
6f968db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ build | |
composer.lock | ||
docs | ||
vendor | ||
.idea | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,5 +39,5 @@ | |
}, | ||
"config": { | ||
"sort-packages": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
use DateTime; | ||
use DateTimeZone; | ||
use DateTimeImmutable; | ||
use DateTimeInterface; | ||
use Spatie\OpeningHours\Helpers\Arr; | ||
use Spatie\OpeningHours\Exceptions\Exception; | ||
|
@@ -150,13 +151,17 @@ public function isClosed(): bool | |
return $this->isClosedAt(new DateTime()); | ||
} | ||
|
||
public function nextOpen(DateTimeInterface $dateTime): DateTime | ||
public function nextOpen(DateTimeInterface $dateTime): DateTimeInterface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately changing the return type is a breaking change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nop because your PHP requirement: |
||
{ | ||
if (! ($dateTime instanceof DateTimeImmutable)) { | ||
$dateTime = clone $dateTime; | ||
} | ||
|
||
$openingHoursForDay = $this->forDate($dateTime); | ||
$nextOpen = $openingHoursForDay->nextOpen(Time::fromDateTime($dateTime)); | ||
|
||
while ($nextOpen == false) { | ||
$dateTime | ||
while ($nextOpen === false) { | ||
$dateTime = $dateTime | ||
->modify('+1 day') | ||
->setTime(0, 0, 0); | ||
|
||
|
@@ -166,18 +171,22 @@ public function nextOpen(DateTimeInterface $dateTime): DateTime | |
} | ||
|
||
$nextDateTime = $nextOpen->toDateTime(); | ||
$dateTime->setTime($nextDateTime->format('G'), $nextDateTime->format('i'), 0); | ||
$dateTime = $dateTime->setTime($nextDateTime->format('G'), $nextDateTime->format('i'), 0); | ||
|
||
return $dateTime; | ||
} | ||
|
||
public function nextClose(DateTimeInterface $dateTime): DateTime | ||
public function nextClose(DateTimeInterface $dateTime): DateTimeInterface | ||
{ | ||
if (! ($dateTime instanceof DateTimeImmutable)) { | ||
$dateTime = clone $dateTime; | ||
} | ||
|
||
$openingHoursForDay = $this->forDate($dateTime); | ||
$nextClose = $openingHoursForDay->nextClose(Time::fromDateTime($dateTime)); | ||
|
||
while ($nextClose == false) { | ||
$dateTime | ||
while ($nextClose === false) { | ||
$dateTime = $dateTime | ||
->modify('+1 day') | ||
->setTime(0, 0, 0); | ||
|
||
|
@@ -187,7 +196,7 @@ public function nextClose(DateTimeInterface $dateTime): DateTime | |
} | ||
|
||
$nextDateTime = $nextClose->toDateTime(); | ||
$dateTime->setTime($nextDateTime->format('G'), $nextDateTime->format('i'), 0); | ||
$dateTime = $dateTime->setTime($nextDateTime->format('G'), $nextDateTime->format('i'), 0); | ||
|
||
return $dateTime; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this, it should be in a global gitignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaned, it will disappear if you re-open the PR.