| 1 | <?php |
||
| 11 | class DatetimeValidator extends AbstractFormatValidator |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Validate that the input is a valid ISO8601 formatted date. |
||
| 15 | * |
||
| 16 | * @return boolean Whether the input is valid. |
||
| 17 | */ |
||
| 18 | 10 | protected function formatDefault() |
|
| 19 | { |
||
| 20 | 10 | if (1 === preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/', $this->input)) { |
|
| 21 | return (false !== \DateTime::createFromFormat(DATE_ISO8601, $this->input)); |
||
| 22 | } |
||
| 23 | |||
| 24 | 10 | if ($this->formatDate('Y-m-d H:i:s')) { |
|
| 25 | 2 | return true; |
|
| 26 | } |
||
| 27 | |||
| 28 | 10 | if ($this->formatDate('Y-m-d')) { |
|
| 29 | 3 | return true; |
|
| 30 | } |
||
| 31 | |||
| 32 | 10 | if ($this->formatDate('H:i:s')) { |
|
| 33 | 2 | return true; |
|
| 34 | } |
||
| 35 | |||
| 36 | 8 | return false; |
|
| 37 | } |
||
| 38 | |||
| 39 | |||
| 40 | /** |
||
| 41 | * Validate that the input is a valid date in the specified format. |
||
| 42 | * |
||
| 43 | * @param string $format The date format to validate against. |
||
| 44 | * |
||
| 45 | * @return boolean Whether the input is valid. |
||
| 46 | */ |
||
| 47 | 10 | protected function formatDate($format) |
|
| 53 | } |
||
| 54 |