Skip to content

Commit

Permalink
HP-2166 Add Bill Usage Interval (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeriyShnurovoy authored Nov 14, 2024
1 parent 0786e14 commit d568ee3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/action/UsageInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
1 change: 1 addition & 0 deletions src/bill/Bill.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function getUniqueString(): string

public function getUsageInterval(): UsageInterval
{
return $this->usageInterval;
}

public function calculatePrice()
Expand Down

0 comments on commit d568ee3

Please sign in to comment.