Skip to content

Commit

Permalink
Allow 'dateTimeClass' in mergeOverlappingRanges and createAndMergeOve…
Browse files Browse the repository at this point in the history
…rlappingRanges

Fix #266
  • Loading branch information
kylekatarnls committed Feb 11, 2025
1 parent 6c90d8c commit fc50d40
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/OpeningHours.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static function createFromStructuredData(
* @param array $excludedKeys keys to ignore from parsing
* @return array
*/
public static function mergeOverlappingRanges(array $data, array $excludedKeys = ['data', 'filters', 'overflow']): array
public static function mergeOverlappingRanges(array $data, array $excludedKeys = ['data', 'dateTimeClass', 'filters', 'overflow']): array
{
$result = [];
$ranges = [];
Expand Down
27 changes: 27 additions & 0 deletions tests/OpeningHoursFillTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ function (DateTimeImmutable $date) use ($typicalDay) {
public function it_should_merge_ranges_on_explicitly_create_from_overlapping_ranges()
{
$hours = OpeningHours::createAndMergeOverlappingRanges([
'dateTimeClass' => DateTimeImmutable::class,
'monday' => [
'08:00-12:00',
'08:00-12:00',
Expand Down Expand Up @@ -314,6 +315,32 @@ public function it_should_merge_ranges_on_explicitly_create_from_overlapping_ran
], $dump['tuesday']);
}

#[Test]
public function it_should_merge_ranges_and_keep_date_time_class()
{
$hours = OpeningHours::createAndMergeOverlappingRanges([
'dateTimeClass' => DateTimeImmutable::class,
'monday' => [
'08:00-12:00',
'08:00-12:00',
'11:30-13:30',
'13:00-18:00',
],
'tuesday' => [
'08:00-12:00',
'11:30-13:30',
'15:00-18:00',
'16:00-17:00',
'19:00-20:00',
'20:00-21:00',
],
]);
$date = $hours->nextOpen(new DateTimeImmutable('2018-12-03'));
$this->assertInstanceOf(DateTimeImmutable::class, $date);

$this->assertSame('2018-12-03 08:00', $date->format('Y-m-d H:i'));
}

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

0 comments on commit fc50d40

Please sign in to comment.