diff --git a/src/action/UsageInterval.php b/src/action/UsageInterval.php index e13ca20a..6b8693db 100644 --- a/src/action/UsageInterval.php +++ b/src/action/UsageInterval.php @@ -178,9 +178,15 @@ public function ratioOfMonth(): float */ public function extend(self $other): self { + $newStart = min($this->start, $other->start); + $newEnd = max($this->end, $other->end); + + if ($newStart > $newEnd) { + throw new InvalidArgumentException('Cannot extend intervals: resulting interval would be invalid'); + } return new self( - min($this->start, $other->start), - max($this->end, $other->end), + $newStart, + $newEnd, ); } } diff --git a/src/bill/Bill.php b/src/bill/Bill.php index 3fadc274..6e833f59 100755 --- a/src/bill/Bill.php +++ b/src/bill/Bill.php @@ -111,6 +111,7 @@ public function getUniqueString(): string public function getUsageInterval(): UsageInterval { + return $this->usageInterval; } public function calculatePrice()