Skip to content

Commit 7b3fdff

Browse files
authored
Merge pull request #139 from brummbar/isbefore-period-bounds
Consider bounds when checking if a period is before another.
2 parents 5fcc4f3 + b1ca39a commit 7b3fdff

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Period.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ public function durationLessThan(Period|Duration|DateInterval|string $duration):
488488
public function isBefore(Period|DatePoint|DateTimeInterface|string $timeSlot): bool
489489
{
490490
if ($timeSlot instanceof self) {
491-
return $this->endDate <= $timeSlot->startDate;
491+
return $this->endDate <= $timeSlot->startDate && !$this->meetsOnStart($timeSlot);
492492
}
493493

494494
$datePoint = self::filterDatePoint($timeSlot);

src/PeriodRelationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ public static function isBeforeProvider(): array
9090
'exclude start date is before interval' => [
9191
'interval' => Period::after('2012-01-01', '1 MONTH', Bounds::ExcludeStartIncludeEnd),
9292
'input' => Period::fromMonth(2012, 2),
93-
'expected' => true,
93+
'expected' => false,
9494
],
9595
'exclude start date is not before interval' => [
9696
'interval' => Period::after('2012-01-01', '1 MONTH', Bounds::ExcludeStartIncludeEnd),
97-
'input' => Period::fromMonth(2012, 2),
97+
'input' => Period::fromMonth(2012, 3),
9898
'expected' => true,
9999
],
100100
'exclude start date abuts interval start date' => [
@@ -155,10 +155,10 @@ public static function isAfterProvider(): array
155155
'exclude start date is before interval' => [
156156
'interval' => Period::fromMonth(2012, 2),
157157
'input' => Period::after('2012-01-01', '1 MONTH', Bounds::ExcludeStartIncludeEnd),
158-
'expected' => true,
158+
'expected' => false,
159159
],
160160
'exclude start date is not before interval' => [
161-
'interval' => Period::fromMonth(2012, 2),
161+
'interval' => Period::fromMonth(2012, 3),
162162
'input' => Period::after('2012-01-01', '1 MONTH', Bounds::ExcludeStartIncludeEnd),
163163
'expected' => true,
164164
],

0 commit comments

Comments
 (0)