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 |
||
155 | |||
156 | /** |
||
157 | * Creates a DateInterval object based on a given number of seconds. |
||
158 | * |
||
159 | * @param int $seconds |
||
160 | * |
||
161 | * @return DateInterval |
||
162 | */ |
||
163 | public static function secondsToInterval(int $seconds): DateInterval |
||
169 | |||
170 | /** |
||
171 | * Returns the number of seconds that a given DateInterval object spans. |
||
172 | * |
||
173 | * @param DateInterval $dateInterval |
||
174 | * |
||
175 | * @return int |
||
176 | */ |
||
177 | public static function intervalToSeconds(DateInterval $dateInterval): int |
||
184 | |||
185 | /** |
||
186 | * Returns true if interval string is a valid interval. |
||
187 | * |
||
188 | * @param string $intervalString |
||
189 | * |
||
190 | * @return bool |
||
191 | */ |
||
192 | public static function isValidIntervalString(string $intervalString): bool |
||
203 | } |
||
204 |