Skip to content

Commit

Permalink
Merge pull request #256 from spatie/fix/issue-255-first-minute-handling
Browse files Browse the repository at this point in the history
Handle opening-time with the first minute of day only
  • Loading branch information
kylekatarnls authored Oct 24, 2024
2 parents 11f7e02 + f4a3034 commit 5a031ad
Show file tree
Hide file tree
Showing 2 changed files with 39 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 @@ -504,7 +504,7 @@ public function nextOpen(
$this->isOpenAt($this->copyAndModify($dateTime, '-1 second'))
) {
return $this->getDateWithTimezone(
$this->nextOpen($dateTime->modify('+1 minute')),
$this->nextOpen($dateTime->modify('+1 second')),
$outputTimezone
);
}
Expand Down
38 changes: 38 additions & 0 deletions tests/OpeningHoursTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;
use Spatie\OpeningHours\Day;
use Spatie\OpeningHours\Exceptions\InvalidDateRange;
Expand Down Expand Up @@ -1647,4 +1648,41 @@ public function testRangesExceptionOverlap()
],
]);
}

#[TestWith([true])]
#[TestWith([false])]
public function testFirstDayMinuteOpenEveryDay(bool $overflow)
{
$config = [
'monday' => ['00:01-00:00'],
'tuesday' => ['00:01-00:00'],
'wednesday' => ['00:01-00:00'],
'thursday' => ['00:01-00:00'],
'friday' => ['00:01-00:00'],
'saturday' => ['00:01-00:00'],
'sunday' => ['00:01-00:00'],
'overflow' => $overflow,
];
$openingHoursObject = OpeningHours::create($config);

$nextOpen = $openingHoursObject->nextOpen(new DateTimeImmutable('2024-10-22 00:00:00'));

$this->assertSame('2024-10-22 00:01:00.000000', $nextOpen->format('Y-m-d H:i:s.u'));

$nextOpen = $openingHoursObject->nextOpen(new DateTimeImmutable('2024-10-22 00:00:30'));

$this->assertSame('2024-10-22 00:01:00.000000', $nextOpen->format('Y-m-d H:i:s.u'));

$nextOpen = $openingHoursObject->nextOpen(new DateTimeImmutable('2024-10-22 00:01:00'));

$this->assertSame('2024-10-23 00:01:00.000000', $nextOpen->format('Y-m-d H:i:s.u'));

$nextOpen = $openingHoursObject->nextOpen(new DateTimeImmutable('2024-10-22 00:01:00'));

$this->assertSame('2024-10-23 00:01:00.000000', $nextOpen->format('Y-m-d H:i:s.u'));

$nextOpen = $openingHoursObject->nextOpen(new DateTimeImmutable('2024-10-22 23:59:59.999999'));

$this->assertSame('2024-10-23 00:01:00.000000', $nextOpen->format('Y-m-d H:i:s.u'));
}
}

0 comments on commit 5a031ad

Please sign in to comment.