1 | <?php |
||
19 | class DateIntervalHelper |
||
20 | { |
||
21 | // Constants |
||
22 | // ========================================================================= |
||
23 | |||
24 | /** |
||
25 | * Number of seconds in a minute. |
||
26 | * |
||
27 | * @var int |
||
28 | */ |
||
29 | const SECONDS_MINUTE = 60; |
||
30 | |||
31 | /** |
||
32 | * Number of seconds in an hour. |
||
33 | * |
||
34 | * @var int |
||
35 | */ |
||
36 | const SECONDS_HOUR = 3600; |
||
37 | |||
38 | /** |
||
39 | * Number of seconds in a day. |
||
40 | * |
||
41 | * @var int |
||
42 | */ |
||
43 | const SECONDS_DAY = 86400; |
||
44 | |||
45 | /** |
||
46 | * The number of seconds in a year. |
||
47 | * |
||
48 | * @var int |
||
49 | */ |
||
50 | const SECONDS_YEAR = 31536000; |
||
51 | |||
52 | // Public Methods |
||
53 | // ========================================================================= |
||
54 | |||
55 | /** |
||
56 | * @param int $seconds The number of seconds |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | public static function secondsToHumanTimeDuration(int $seconds): string |
||
103 | |||
104 | /** |
||
105 | * Returns the interval in a human-friendly string. |
||
106 | * |
||
107 | * @param DateInterval $dateInterval |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | public static function humanDurationFromInterval(DateInterval $dateInterval): string |
||
151 | |||
152 | /** |
||
153 | * Creates a DateInterval object based on a given number of seconds. |
||
154 | * |
||
155 | * @param int $seconds |
||
156 | * |
||
157 | * @return DateInterval |
||
158 | */ |
||
159 | public static function secondsToInterval(int $seconds): DateInterval |
||
165 | |||
166 | /** |
||
167 | * Returns the number of seconds that a given DateInterval object spans. |
||
168 | * |
||
169 | * @param DateInterval $dateInterval |
||
170 | * @return int |
||
171 | * @throws \Exception |
||
172 | */ |
||
173 | public static function intervalToSeconds(DateInterval $dateInterval): int |
||
180 | |||
181 | /** |
||
182 | * Returns true if interval string is a valid interval. |
||
183 | * |
||
184 | * @param string $intervalString |
||
185 | * |
||
186 | * @return bool |
||
187 | */ |
||
188 | public static function isValidIntervalString(string $intervalString): bool |
||
199 | } |
||
200 |