|
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
|
|
|
/** |
|
14
|
|
|
* @var DateStyle|null |
|
15
|
|
|
*/ |
|
16
|
|
|
private $dateStyle; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var DateStyle|null; |
|
20
|
|
|
*/ |
|
21
|
|
|
private $timeStyle; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var bool |
|
25
|
|
|
*/ |
|
26
|
|
|
private $ignoresTimeZone = false; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var bool |
|
30
|
|
|
*/ |
|
31
|
|
|
private $isRelative = false; |
|
32
|
|
|
|
|
33
|
9 |
|
public function __construct(?string $key = null, ?DateTimeImmutable $date = null, ?string $label = null) |
|
34
|
|
|
{ |
|
35
|
9 |
|
parent::__construct($key, null, $label); |
|
36
|
|
|
|
|
37
|
9 |
|
if ($date !== null) { |
|
38
|
9 |
|
$this->setDate($date); |
|
39
|
|
|
} |
|
40
|
9 |
|
} |
|
41
|
|
|
|
|
42
|
9 |
|
public function setDate(DateTimeImmutable $date): void |
|
43
|
|
|
{ |
|
44
|
9 |
|
parent::setValue($date->format(DateTimeImmutable::W3C)); |
|
|
|
|
|
|
45
|
9 |
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
public function setDateStyle(DateStyle $dateStyle): void |
|
48
|
|
|
{ |
|
49
|
1 |
|
$this->dateStyle = $dateStyle; |
|
50
|
1 |
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
public function setTimeStyle(DateStyle $timeStyle): void |
|
53
|
|
|
{ |
|
54
|
1 |
|
$this->timeStyle = $timeStyle; |
|
55
|
1 |
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
public function ignoresTimeZone(): void |
|
58
|
|
|
{ |
|
59
|
1 |
|
$this->ignoresTimeZone = true; |
|
60
|
1 |
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
public function isRelative(): void |
|
63
|
|
|
{ |
|
64
|
1 |
|
$this->isRelative = true; |
|
65
|
1 |
|
} |
|
66
|
|
|
|
|
67
|
9 |
|
public function getMetadata(): array |
|
68
|
|
|
{ |
|
69
|
9 |
|
$data = parent::getMetadata(); |
|
70
|
|
|
|
|
71
|
9 |
|
if ($this->dateStyle) { |
|
72
|
1 |
|
$data['dateStyle'] = $this->dateStyle->getValue(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
9 |
|
if ($this->timeStyle) { |
|
76
|
1 |
|
$data['timeStyle'] = $this->timeStyle->getValue(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
9 |
|
if ($this->ignoresTimeZone) { |
|
80
|
1 |
|
$data['ignoresTimeZone'] = $this->ignoresTimeZone; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
9 |
|
if ($this->isRelative) { |
|
84
|
1 |
|
$data['isRelative'] = $this->isRelative; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
9 |
|
return $data; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.