Lines 100.00% 3 / 3
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
HistoryWindow 100.00% 3 / 3 100.00% 2 / 2 3 100.00% 1 / 1
 __construct 100.00% 2 / 2 100.00% 1 / 1 2
 getDuration 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Contracts\History;
6
7use Stewart\Contracts\Exception\HistoryError;
8use Stewart\Contracts\Exception\HistoryException;
9use Stewart\Contracts\Time\Duration;
10use Stewart\Contracts\Time\Instant;
11
12final readonly class HistoryWindow
13{
14    /** @throws HistoryException */
15    public function __construct(
16        public Instant $startsAt,
17        public Instant $endsAt,
18    ) {
19        if (!$endsAt->isAfter($startsAt)) {
20            throw HistoryException::createForReason(HistoryError::WindowInvalid, startsAt: (string) $startsAt, endsAt: (string) $endsAt);
21        }
22    }
23
24    public function getDuration(): Duration
25    {
26        return $this->endsAt->elapsedSince($this->startsAt);
27    }
28}