Jyxo\Input\Validator\IsDateTime::isValid PHP Method

isValid() public method

Validates a value.
public isValid ( mixed $value ) : boolean
$value mixed Input value
return boolean
    public function isValid($value) : bool
    {
        // Format check
        if (!preg_match('~^(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})$~', (string) $value, $matches)) {
            return false;
        }
        list(, $year, $month, $day, $hour, $minute, $second) = $matches;
        // Date validity check
        if (!checkdate((int) $month, (int) $day, (int) $year)) {
            return false;
        }
        // Time validity check
        if ($hour < 0 || $hour > 23) {
            return false;
        }
        if ($minute < 0 || $minute > 59) {
            return false;
        }
        if ($second < 0 || $second > 59) {
            return false;
        }
        return true;
    }
IsDateTime