Skip to content

Commit 793b060

Browse files
committed
- Allow overflow for structured-data
1 parent d3f3ab7 commit 793b060

4 files changed

+25
-4
lines changed

src/OpeningHours.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ public static function createFromStructuredData(
128128
string|DateTimeZone|null $outputTimezone = null,
129129
): self {
130130
return new static(
131-
OpeningHoursSpecificationParser::create($structuredData)->getOpeningHours(),
131+
array_merge(
132+
// https://schema.org/OpeningHoursSpecification allows overflow by default
133+
['overflow' => true],
134+
OpeningHoursSpecificationParser::create($structuredData)->getOpeningHours(),
135+
),
132136
$timezone,
133137
$outputTimezone,
134138
);
@@ -936,7 +940,7 @@ public function flatMapExceptions(callable $callback): array
936940
public function every(callable $callback): bool
937941
{
938942
return $this->filter(
939-
static fn (OpeningHoursForDay $day) => !$callback($day),
943+
static fn (OpeningHoursForDay $day) => ! $callback($day),
940944
) === [];
941945
}
942946

src/OpeningHoursSpecificationParser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function getOpeningHours(): array
6161
}
6262

6363
/**
64-
* Regular opening hours
64+
* Regular opening hours.
6565
*/
6666
private function addDaysOfWeek(
6767
array $dayOfWeek,

tests/OpeningHoursSpecificationParserTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,23 @@ public function testEmptySpecs(): void
111111
$this->assertTrue($openingHours->isAlwaysClosed());
112112
}
113113

114+
public function testRangeOverNight(): void
115+
{
116+
$openingHours = OpeningHours::createFromStructuredData([
117+
[
118+
'dayOfWeek' => 'Monday',
119+
'opens' => '18:00',
120+
'closes' => '02:00',
121+
],
122+
]);
123+
124+
$this->assertTrue($openingHours->isClosedAt(new DateTimeImmutable('2023-11-27 17:50')));
125+
$this->assertTrue($openingHours->isOpenAt(new DateTimeImmutable('2023-11-27 23:55')));
126+
$this->assertTrue($openingHours->isOpenAt(new DateTimeImmutable('2023-11-27 23:59:59.99')));
127+
$this->assertTrue($openingHours->isOpenAt(new DateTimeImmutable('2023-11-28 01:50')));
128+
$this->assertTrue($openingHours->isClosedAt(new DateTimeImmutable('2023-11-28 19:00')));
129+
}
130+
114131
public function testH24Specs(): void
115132
{
116133
$openingHours = OpeningHours::createFromStructuredData([

tests/OpeningHoursTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ public function it_can_determine_that_its_open_now()
957957
/** @test */
958958
public function it_can_use_day_enum()
959959
{
960-
$openingHours = new class () extends OpeningHours
960+
$openingHours = new class extends OpeningHours
961961
{
962962
public readonly array $days;
963963

0 commit comments

Comments
 (0)