Skip to content
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

Check both start and end to consider a range before/after #251

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Helpers/RangeFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function findCloseInFreeTime(Time $time, TimeRange $timeRange): ?Time

protected function findPreviousRangeInFreeTime(Time $time, TimeRange $timeRange): ?TimeRange
{
return $time->isAfter($timeRange->end()) ? $timeRange : null;
return $time->isAfter($timeRange->end()) && $time->isAfter($timeRange->start()) ? $timeRange : null;
}

protected function findPreviousOpenInFreeTime(Time $time, TimeRange $timeRange): ?Time
Expand Down
14 changes: 14 additions & 0 deletions tests/OpeningHoursOverflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ public function next_close_with_overflow_immutable()
$this->assertSame('2019-04-22 02:00:00', $previousTimeOpen);
}

#[Test]
public function previous_open_and_close_with_overflow_immutable()
{
$openingHours = OpeningHours::create([
'overflow' => true,
'monday' => ['18:00-05:00'],
'tuesday' => ['18:00-05:00'],
]);
$tuesday = new DateTime('2024-06-11 06:00:00');

$this->assertSame('2024-06-10 18:00', $openingHours->previousOpen($tuesday)->format('Y-m-d H:i'));
$this->assertSame('2024-06-11 05:00', $openingHours->previousClose($tuesday)->format('Y-m-d H:i'));
}

#[Test]
public function overflow_on_simple_ranges()
{
Expand Down