1 | <?php |
||
2 | /** |
||
3 | * File was created 01.10.2015 18:02 |
||
4 | * |
||
5 | * @author Karsten J. Gerber <[email protected]> |
||
6 | */ |
||
7 | |||
8 | namespace PeekAndPoke\Component\Psi\Psi; |
||
9 | |||
10 | use PeekAndPoke\Component\Psi\UnaryFunction; |
||
11 | |||
12 | /** |
||
13 | * IsDateString checks whether the given string is a valid ISO_8601 date string |
||
14 | * |
||
15 | * @see IsDateStringTest |
||
16 | * |
||
17 | * @author Karsten J. Gerber <[email protected]> |
||
18 | */ |
||
19 | class IsDateString implements UnaryFunction |
||
20 | { |
||
21 | /** |
||
22 | * @param mixed $input |
||
23 | * |
||
24 | * @return bool |
||
25 | */ |
||
26 | 28 | public function __invoke($input) |
|
27 | { |
||
28 | 28 | return self::isValidDateString($input); |
|
29 | } |
||
30 | |||
31 | /** |
||
32 | * @param string $str |
||
33 | * |
||
34 | * @return bool |
||
35 | */ |
||
36 | 28 | public static function isValidDateString($str) |
|
37 | { |
||
38 | 28 | if (! is_string($str)) { |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
39 | 3 | return false; |
|
40 | } |
||
41 | |||
42 | 25 | return strtotime($str) !== false || |
|
43 | 25 | preg_match('/^(\d{4})-(\d{2})-(\d{2})T((\d{2}):(\d{2}):(\d{2})(\.\d{1-6}(Z)?)?([+-]\d{2}:\d{2})?)$/', $str); |
|
44 | } |
||
45 | } |
||
46 |