From f4a3034ff08516b2584699ad0bb9a73aabd55c44 Mon Sep 17 00:00:00 2001 From: kylekatarnls Date: Thu, 24 Oct 2024 13:39:17 +0200 Subject: [PATCH] Handle opening-time with the first minute of day only Fix #255 --- src/OpeningHours.php | 2 +- tests/OpeningHoursTest.php | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/OpeningHours.php b/src/OpeningHours.php index 948719f..aa5ba51 100644 --- a/src/OpeningHours.php +++ b/src/OpeningHours.php @@ -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 ); } diff --git a/tests/OpeningHoursTest.php b/tests/OpeningHoursTest.php index 7b89e75..ac11acf 100644 --- a/tests/OpeningHoursTest.php +++ b/tests/OpeningHoursTest.php @@ -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; @@ -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')); + } }