Total Complexity | 10 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php |
||
19 | final class Utils |
||
20 | { |
||
21 | public static function createDateInterval($value) |
||
22 | { |
||
23 | if ($value instanceOf \DateInterval) { |
||
24 | return $value; |
||
25 | } |
||
26 | |||
27 | if (is_numeric($value)) { |
||
28 | $delay = new \DateInterval(sprintf("PT%dS", abs((int) $value))); |
||
29 | $delay->invert = ($value < 0) ? 1 : 0; |
||
30 | |||
31 | return $delay; |
||
32 | } |
||
33 | |||
34 | if (is_string($value)) { |
||
35 | try { |
||
36 | // first try ISO 8601 duration specification |
||
37 | $delay = new \DateInterval($value); |
||
38 | } catch (\Exception $e) { |
||
39 | // then try normal date parser |
||
40 | $delay = \DateInterval::createFromDateString($value); |
||
41 | } |
||
42 | return $delay; |
||
43 | } |
||
44 | |||
45 | return new \DateInterval('PT0S'); |
||
46 | } |
||
47 | |||
48 | public static function createDateTime($value) |
||
66 | } |
||
67 | } |
||
68 |