1 | <?php |
||
10 | class Time implements \JsonSerializable |
||
11 | { |
||
12 | /** |
||
13 | * The hours part of the time. |
||
14 | * |
||
15 | * @var integer |
||
16 | */ |
||
17 | protected $hours; |
||
18 | |||
19 | /** |
||
20 | * The minutes part of the time. |
||
21 | * |
||
22 | * @var integer |
||
23 | */ |
||
24 | protected $minutes = 0; |
||
25 | |||
26 | /** |
||
27 | * The seconds part of the time. |
||
28 | * |
||
29 | * @var integer |
||
30 | */ |
||
31 | protected $seconds = 0; |
||
32 | |||
33 | /** |
||
34 | * @param integer $hours The hours. |
||
35 | * @param integer $minutes The minutes. |
||
36 | * @param integer $seconds The seconds. |
||
37 | */ |
||
38 | 282 | public function __construct(int $hours, int $minutes = 0, int $seconds = 0) |
|
44 | |||
45 | /** |
||
46 | * Checks if this time is before or equal to an other time. |
||
47 | * |
||
48 | * @param Time $other The time to compare it against. |
||
49 | * @return boolean |
||
50 | */ |
||
51 | 108 | public function isBeforeOrEqual(Time $other): bool |
|
55 | |||
56 | /** |
||
57 | * Checks if this time is after or equal to an other time. |
||
58 | * |
||
59 | * @param Time $other The time to compare it against. |
||
60 | * @return boolean |
||
61 | */ |
||
62 | 180 | public function isAfterOrEqual(Time $other): bool |
|
66 | |||
67 | /** |
||
68 | * Check if this time is equal to another time. |
||
69 | * |
||
70 | * @param Time $other The time to compare it against. |
||
71 | * @return boolean |
||
72 | */ |
||
73 | 9 | public function isEqual(Time $other): bool |
|
77 | |||
78 | /** |
||
79 | * Get the time representation in seconds. |
||
80 | * |
||
81 | * @return integer |
||
82 | */ |
||
83 | 216 | public function toSeconds(): int |
|
87 | |||
88 | /** |
||
89 | * Set the hours. |
||
90 | * |
||
91 | * @param integer $hours The hours. |
||
92 | */ |
||
93 | public function setHours(int $hours): void |
||
99 | |||
100 | 279 | /** |
|
101 | * Get the hours. |
||
102 | 279 | * |
|
103 | * @return integer |
||
104 | */ |
||
105 | public function getHours(): int |
||
109 | |||
110 | 165 | /** |
|
111 | * Set the minutes. |
||
112 | 165 | * |
|
113 | * @param integer $minutes The minutes |
||
114 | */ |
||
115 | public function setMinutes(int $minutes): void |
||
121 | 279 | ||
122 | /** |
||
123 | 279 | * Get the minutes. |
|
124 | * |
||
125 | 279 | * @return integer |
|
126 | */ |
||
127 | 270 | public function getMinutes(): int |
|
131 | |||
132 | /** |
||
133 | * Set the seconds. |
||
134 | * |
||
135 | * @param integer $seconds The seconds. |
||
136 | */ |
||
137 | 126 | public function setSeconds(int $seconds): void |
|
143 | |||
144 | /** |
||
145 | * Get the seconds. |
||
146 | * |
||
147 | * @return integer |
||
148 | 270 | */ |
|
149 | public function getSeconds(): int |
||
153 | |||
154 | 261 | /** |
|
155 | * Check if the time elements are valid. |
||
156 | 261 | * |
|
157 | * @param integer $hours The hours. |
||
158 | * @param integer $minutes The minutes. |
||
159 | * @param integer $seconds The seconds. |
||
160 | * @return boolean |
||
161 | * @throws \InvalidArgumentException If the elements are not valid. |
||
162 | */ |
||
163 | private function timeElementsAreValid($hours, $minutes, $seconds): bool |
||
181 | 282 | ||
182 | 282 | /** |
|
183 | * {@inheritdoc} |
||
184 | 282 | */ |
|
185 | 9 | public function jsonSerialize() |
|
193 | |||
194 | /** |
||
195 | * Returns a string representation of the time. |
||
196 | * |
||
197 | * @return string |
||
198 | 12 | */ |
|
199 | public function __toString() |
||
203 | } |
||
204 |