1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace LauLamanApps\ApplePassbook\MetaData\Field; |
||
6 | |||
7 | use DateTimeImmutable; |
||
8 | use LauLamanApps\ApplePassbook\Exception\InvalidArgumentException; |
||
9 | use LauLamanApps\ApplePassbook\Style\DateStyle; |
||
10 | |||
11 | class DateField extends Field |
||
12 | { |
||
13 | private DateStyle $dateStyle; |
||
14 | private DateStyle $timeStyle; |
||
15 | private bool $ignoresTimeZone = false; |
||
16 | private bool $isRelative = false; |
||
17 | |||
18 | public function __construct(?string $key = null, ?DateTimeImmutable $date = null, ?string $label = null) |
||
19 | { |
||
20 | parent::__construct($key, null, $label); |
||
21 | |||
22 | if ($date !== null) { |
||
23 | $this->setDate($date); |
||
24 | } |
||
25 | } |
||
26 | |||
27 | public function setDate(DateTimeImmutable $date): void |
||
28 | { |
||
29 | parent::setValue($date->format(DateTimeImmutable::W3C)); |
||
30 | } |
||
31 | |||
32 | public function setDateStyle(DateStyle $dateStyle): void |
||
33 | 9 | { |
|
34 | $this->dateStyle = $dateStyle; |
||
35 | 9 | } |
|
36 | |||
37 | 9 | public function setTimeStyle(DateStyle $timeStyle): void |
|
38 | 9 | { |
|
39 | $this->timeStyle = $timeStyle; |
||
40 | 9 | } |
|
41 | |||
42 | 9 | public function ignoresTimeZone(): void |
|
43 | { |
||
44 | 9 | $this->ignoresTimeZone = true; |
|
45 | 9 | } |
|
46 | |||
47 | 1 | public function isRelative(): void |
|
48 | { |
||
49 | 1 | $this->isRelative = true; |
|
50 | 1 | } |
|
51 | |||
52 | 1 | /** |
|
53 | * @return array<string> |
||
54 | 1 | */ |
|
55 | 1 | public function getMetadata(): array |
|
56 | { |
||
57 | 1 | $data = parent::getMetadata(); |
|
58 | |||
59 | 1 | if (isset($this->dateStyle)) { |
|
60 | 1 | $data['dateStyle'] = $this->dateStyle->getValue(); |
|
61 | } |
||
62 | 1 | ||
63 | if (isset($this->timeStyle)) { |
||
64 | 1 | $data['timeStyle'] = $this->timeStyle->getValue(); |
|
65 | 1 | } |
|
66 | |||
67 | 9 | if ($this->ignoresTimeZone) { |
|
68 | $data['ignoresTimeZone'] = $this->ignoresTimeZone; |
||
69 | 9 | } |
|
70 | |||
71 | 9 | if ($this->isRelative) { |
|
72 | 1 | $data['isRelative'] = $this->isRelative; |
|
73 | } |
||
74 | |||
75 | 9 | return $data; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
76 | 1 | } |
|
77 | } |
||
78 |