From b1ca39af0d70b55b524d53442ebd727a95a51226 Mon Sep 17 00:00:00 2001 From: Francesco Sardara Date: Wed, 15 Oct 2025 16:19:31 +0200 Subject: [PATCH] Consider bounds when checking if a period is before another. --- src/Period.php | 2 +- src/PeriodRelationTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Period.php b/src/Period.php index 621230a..f87d390 100644 --- a/src/Period.php +++ b/src/Period.php @@ -488,7 +488,7 @@ public function durationLessThan(Period|Duration|DateInterval|string $duration): public function isBefore(Period|DatePoint|DateTimeInterface|string $timeSlot): bool { if ($timeSlot instanceof self) { - return $this->endDate <= $timeSlot->startDate; + return $this->endDate <= $timeSlot->startDate && !$this->meetsOnStart($timeSlot); } $datePoint = self::filterDatePoint($timeSlot); diff --git a/src/PeriodRelationTest.php b/src/PeriodRelationTest.php index 97a069d..9a511c8 100644 --- a/src/PeriodRelationTest.php +++ b/src/PeriodRelationTest.php @@ -90,11 +90,11 @@ public static function isBeforeProvider(): array 'exclude start date is before interval' => [ 'interval' => Period::after('2012-01-01', '1 MONTH', Bounds::ExcludeStartIncludeEnd), 'input' => Period::fromMonth(2012, 2), - 'expected' => true, + 'expected' => false, ], 'exclude start date is not before interval' => [ 'interval' => Period::after('2012-01-01', '1 MONTH', Bounds::ExcludeStartIncludeEnd), - 'input' => Period::fromMonth(2012, 2), + 'input' => Period::fromMonth(2012, 3), 'expected' => true, ], 'exclude start date abuts interval start date' => [ @@ -155,10 +155,10 @@ public static function isAfterProvider(): array 'exclude start date is before interval' => [ 'interval' => Period::fromMonth(2012, 2), 'input' => Period::after('2012-01-01', '1 MONTH', Bounds::ExcludeStartIncludeEnd), - 'expected' => true, + 'expected' => false, ], 'exclude start date is not before interval' => [ - 'interval' => Period::fromMonth(2012, 2), + 'interval' => Period::fromMonth(2012, 3), 'input' => Period::after('2012-01-01', '1 MONTH', Bounds::ExcludeStartIncludeEnd), 'expected' => true, ],