1 | <?php |
||
17 | abstract class AbstractTimestamp extends \DateTime implements AccessorInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | const DEFAULT_FORMAT = 'F d, Y H:m'; |
||
23 | |||
24 | /** |
||
25 | * @var \DateTimeInterface |
||
26 | */ |
||
27 | private $initial = false; |
||
28 | |||
29 | /** |
||
30 | * @param string $value |
||
31 | * @param array $context |
||
32 | */ |
||
33 | public function __construct($value, array $context) |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | public function setValue($data) |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | * |
||
54 | * @return \DateTimeInterface |
||
55 | */ |
||
56 | public function packValue() |
||
60 | |||
61 | /** |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function hasChanges(): bool |
||
68 | |||
69 | /** |
||
70 | * Reset state. |
||
71 | */ |
||
72 | public function flushChanges() |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function jsonSerialize() |
||
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | public function __toString() |
||
92 | |||
93 | /** |
||
94 | * @return array |
||
95 | */ |
||
96 | public function __debugInfo() |
||
103 | |||
104 | /** |
||
105 | * Fetch timestamp from input value. |
||
106 | * |
||
107 | * @param mixed $value |
||
108 | * |
||
109 | * @return int |
||
110 | */ |
||
111 | abstract protected function fetchTimestamp($value): int; |
||
112 | |||
113 | /** |
||
114 | * Helper method, convert input variable to a valid timestamp. Can accept timestamp (will be |
||
115 | * converted to an int) or valid datetime string. Timezone of input datetime string can be set. |
||
116 | * |
||
117 | * @param string|int $datetime Timestamp or valid datetime string. |
||
118 | * @param \DateTimeZone $timezone Source timezone. |
||
119 | * |
||
120 | * @return int|null |
||
121 | */ |
||
122 | protected function castTimestamp($datetime, \DateTimeZone $timezone = null) |
||
144 | } |