diff --git a/lib/Service/Appointments/AvailabilityGenerator.php b/lib/Service/Appointments/AvailabilityGenerator.php index 5eba70200..fdf0b5616 100644 --- a/lib/Service/Appointments/AvailabilityGenerator.php +++ b/lib/Service/Appointments/AvailabilityGenerator.php @@ -70,8 +70,8 @@ class AvailabilityGenerator { // when the user opens the page at 10:17. // But only do this when the time isn't already a "pretty" time if ($earliestStart % $config->getIncrement() !== 0) { - $roundTo = (int)round(($config->getIncrement()) / 300) * 300; - $earliestStart = (int)ceil($earliestStart / $roundTo) * $roundTo; + $roundTo = (int)(round(($config->getIncrement()) / 300) * 300); + $earliestStart = (int)(ceil($earliestStart / $roundTo) * $roundTo); } $latestEnd = min( diff --git a/tests/php/unit/Service/Appointments/AvailabilityGeneratorTest.php b/tests/php/unit/Service/Appointments/AvailabilityGeneratorTest.php index 33def004f..8664e5b08 100644 --- a/tests/php/unit/Service/Appointments/AvailabilityGeneratorTest.php +++ b/tests/php/unit/Service/Appointments/AvailabilityGeneratorTest.php @@ -119,6 +119,48 @@ class AvailabilityGeneratorTest extends TestCase { ); } + public function testNoAvailabilityQuarterHourIncrementsFourtyFiveMinutesLenght(): void { + $config = new AppointmentConfig(); + $config->setLength(2700); // 45 minutes + $config->setIncrement(900); // 15 minutes + $config->setAvailability(null); + + $this->timeFactory->expects(self::once()) + ->method('getTime') + ->willReturn(1709546400); + + $sdate = new \DateTime('2024-03-04 10:00'); + $edate = new \DateTime('2024-03-04 10:45'); + + $slots = $this->generator->generate($config, $sdate->getTimestamp(), $edate->getTimestamp()); + + self::assertCount(1, $slots); + self::assertEquals(0, ($slots[0]->getStart() % $config->getIncrement())); + self::assertEquals(45 * 60, ($slots[0]->getEnd() - $slots[0]->getStart())); + self::assertEquals( + [new Interval(1709546400, 1709549100)], + $slots, + ); + } + + public function testNoAvailabilityZeroTo2700QuarterHourIncrementsFourtyFiveMinutesLenght(): void { + $config = new AppointmentConfig(); + $config->setLength(2700); // 45 minutes + $config->setIncrement(900); // 15 minutes + $config->setAvailability(null); + + $slots = $this->generator->generate($config, 0, 2700); + + self::assertCount(1, $slots); + self::assertEquals(0, $slots[0]->getStart() % 2700); + self::assertEquals(45 * 60, ($slots[0]->getEnd() - $slots[0]->getStart())); + self::assertEquals( + [new Interval(0, 45 * 60)], + $slots, + ); + } + + public function testNoAvailabilitySetRoundWithRealLifeTimesUgly(): void { $config = new AppointmentConfig(); $config->setLength(900);