1 | <?php |
||
23 | class DateIntervalHelper |
||
24 | { |
||
25 | // Constants |
||
26 | // ========================================================================= |
||
27 | |||
28 | /** |
||
29 | * Number of seconds in a minute. |
||
30 | * |
||
31 | * @var int |
||
32 | */ |
||
33 | const SECONDS_MINUTE = 60; |
||
34 | |||
35 | /** |
||
36 | * Number of seconds in an hour. |
||
37 | * |
||
38 | * @var int |
||
39 | */ |
||
40 | const SECONDS_HOUR = 3600; |
||
41 | |||
42 | /** |
||
43 | * Number of seconds in a day. |
||
44 | * |
||
45 | * @var int |
||
46 | */ |
||
47 | const SECONDS_DAY = 86400; |
||
48 | |||
49 | /** |
||
50 | * The number of seconds in a year. |
||
51 | * |
||
52 | * @var int |
||
53 | */ |
||
54 | const SECONDS_YEAR = 31536000; |
||
55 | |||
56 | // Public Methods |
||
57 | // ========================================================================= |
||
58 | |||
59 | /** |
||
60 | * @param int $seconds The number of seconds |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | public static function secondsToHumanTimeDuration(int $seconds): string |
||
107 | |||
108 | /** |
||
109 | * Returns the interval in a human-friendly string. |
||
110 | * |
||
111 | * @param DateInterval $dateInterval |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | 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 | * |
||
171 | * @return int |
||
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 |