Skip to content

Commit 5a031ad

Browse files
authored
Merge pull request #256 from spatie/fix/issue-255-first-minute-handling
Handle opening-time with the first minute of day only
2 parents 11f7e02 + f4a3034 commit 5a031ad

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/OpeningHours.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ public function nextOpen(
504504
$this->isOpenAt($this->copyAndModify($dateTime, '-1 second'))
505505
) {
506506
return $this->getDateWithTimezone(
507-
$this->nextOpen($dateTime->modify('+1 minute')),
507+
$this->nextOpen($dateTime->modify('+1 second')),
508508
$outputTimezone
509509
);
510510
}

tests/OpeningHoursTest.php

+38
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use InvalidArgumentException;
99
use PHPUnit\Framework\Attributes\DataProvider;
1010
use PHPUnit\Framework\Attributes\Test;
11+
use PHPUnit\Framework\Attributes\TestWith;
1112
use PHPUnit\Framework\TestCase;
1213
use Spatie\OpeningHours\Day;
1314
use Spatie\OpeningHours\Exceptions\InvalidDateRange;
@@ -1647,4 +1648,41 @@ public function testRangesExceptionOverlap()
16471648
],
16481649
]);
16491650
}
1651+
1652+
#[TestWith([true])]
1653+
#[TestWith([false])]
1654+
public function testFirstDayMinuteOpenEveryDay(bool $overflow)
1655+
{
1656+
$config = [
1657+
'monday' => ['00:01-00:00'],
1658+
'tuesday' => ['00:01-00:00'],
1659+
'wednesday' => ['00:01-00:00'],
1660+
'thursday' => ['00:01-00:00'],
1661+
'friday' => ['00:01-00:00'],
1662+
'saturday' => ['00:01-00:00'],
1663+
'sunday' => ['00:01-00:00'],
1664+
'overflow' => $overflow,
1665+
];
1666+
$openingHoursObject = OpeningHours::create($config);
1667+
1668+
$nextOpen = $openingHoursObject->nextOpen(new DateTimeImmutable('2024-10-22 00:00:00'));
1669+
1670+
$this->assertSame('2024-10-22 00:01:00.000000', $nextOpen->format('Y-m-d H:i:s.u'));
1671+
1672+
$nextOpen = $openingHoursObject->nextOpen(new DateTimeImmutable('2024-10-22 00:00:30'));
1673+
1674+
$this->assertSame('2024-10-22 00:01:00.000000', $nextOpen->format('Y-m-d H:i:s.u'));
1675+
1676+
$nextOpen = $openingHoursObject->nextOpen(new DateTimeImmutable('2024-10-22 00:01:00'));
1677+
1678+
$this->assertSame('2024-10-23 00:01:00.000000', $nextOpen->format('Y-m-d H:i:s.u'));
1679+
1680+
$nextOpen = $openingHoursObject->nextOpen(new DateTimeImmutable('2024-10-22 00:01:00'));
1681+
1682+
$this->assertSame('2024-10-23 00:01:00.000000', $nextOpen->format('Y-m-d H:i:s.u'));
1683+
1684+
$nextOpen = $openingHoursObject->nextOpen(new DateTimeImmutable('2024-10-22 23:59:59.999999'));
1685+
1686+
$this->assertSame('2024-10-23 00:01:00.000000', $nextOpen->format('Y-m-d H:i:s.u'));
1687+
}
16501688
}

0 commit comments

Comments
 (0)