File tree 4 files changed +25
-4
lines changed
4 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -128,7 +128,11 @@ public static function createFromStructuredData(
128
128
string |DateTimeZone |null $ outputTimezone = null ,
129
129
): self {
130
130
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
+ ),
132
136
$ timezone ,
133
137
$ outputTimezone ,
134
138
);
@@ -936,7 +940,7 @@ public function flatMapExceptions(callable $callback): array
936
940
public function every (callable $ callback ): bool
937
941
{
938
942
return $ this ->filter (
939
- static fn (OpeningHoursForDay $ day ) => !$ callback ($ day ),
943
+ static fn (OpeningHoursForDay $ day ) => ! $ callback ($ day ),
940
944
) === [];
941
945
}
942
946
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ public function getOpeningHours(): array
61
61
}
62
62
63
63
/**
64
- * Regular opening hours
64
+ * Regular opening hours.
65
65
*/
66
66
private function addDaysOfWeek (
67
67
array $ dayOfWeek ,
Original file line number Diff line number Diff line change @@ -111,6 +111,23 @@ public function testEmptySpecs(): void
111
111
$ this ->assertTrue ($ openingHours ->isAlwaysClosed ());
112
112
}
113
113
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
+
114
131
public function testH24Specs (): void
115
132
{
116
133
$ openingHours = OpeningHours::createFromStructuredData ([
Original file line number Diff line number Diff line change @@ -957,7 +957,7 @@ public function it_can_determine_that_its_open_now()
957
957
/** @test */
958
958
public function it_can_use_day_enum ()
959
959
{
960
- $ openingHours = new class () extends OpeningHours
960
+ $ openingHours = new class extends OpeningHours
961
961
{
962
962
public readonly array $ days ;
963
963
You can’t perform that action at this time.
0 commit comments