1 | <?php |
||
11 | use InvalidArgumentException; |
||
12 | |||
13 | final class Timestamp implements SerializableInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var DateTimeInterface |
||
17 | */ |
||
18 | private $startDate; |
||
19 | |||
20 | /** |
||
21 | * @var DateTimeInterface |
||
22 | */ |
||
23 | private $endDate; |
||
24 | |||
25 | /** |
||
26 | * @var EventStatus|null |
||
27 | */ |
||
28 | private $eventStatus; |
||
29 | |||
30 | final public function __construct( |
||
31 | DateTimeInterface $startDate, |
||
32 | DateTimeInterface $endDate, |
||
33 | EventStatus $eventStatus = null |
||
34 | ) { |
||
35 | if ($endDate < $startDate) { |
||
36 | throw new InvalidArgumentException('End date can not be earlier than start date.'); |
||
37 | } |
||
38 | |||
39 | $this->startDate = $startDate; |
||
40 | $this->endDate = $endDate; |
||
41 | } |
||
42 | |||
43 | public function getStartDate(): DateTimeInterface |
||
44 | { |
||
45 | return $this->startDate; |
||
46 | } |
||
47 | |||
48 | public function getEndDate(): DateTimeInterface |
||
49 | { |
||
50 | return $this->endDate; |
||
51 | } |
||
52 | |||
53 | public function getEventStatus(): ?EventStatus |
||
54 | { |
||
55 | return $this->eventStatus; |
||
56 | } |
||
57 | |||
58 | public static function deserialize(array $data): Timestamp |
||
59 | { |
||
60 | return new static( |
||
61 | DateTime::createFromFormat(DateTime::ATOM, $data['startDate']), |
||
62 | DateTime::createFromFormat(DateTime::ATOM, $data['endDate']), |
||
63 | ); |
||
|
|||
64 | } |
||
65 | |||
66 | public function serialize(): array |
||
67 | { |
||
68 | $serialized = [ |
||
69 | 'startDate' => $this->startDate->format(DateTime::ATOM), |
||
92 |