src/DatetimeValidator.php
public function validate($value)
    {
        //Use string's validator
        $return = parent::validate($value);

        //Apply additional rules
        if ($return->status === true && (preg_match(
            '/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/',
            $value,
            $matches
        ))) {
            if (checkdate($matches[2], $matches[3], $matches[1])) {
                $timestamp = strtotime($value);

                //validate formatMinimum
                if ($this->formatMinimum !== null
                    && $timestamp < strtotime($this->formatMinimum)
                ) {
                    $failure = 'formatMinimum';
                    goto error;
                }

                //validate formatMaximum
                if ($this->formatMaximum !== null
                    && $timestamp > strtotime($this->formatMaximum)
                ) {
                    $failure = 'formatMaximum';
                    goto error;
                }

                //Set status to success
                $return->status = true;

                return $return;
            }
        }

        $failure = 'failure';

        error:
        $return->status = false;
        $return->errorObject = new IncorrectParametersException([
            [
                'type' => static::getType(),
                'failure' => $failure
            ]
        ]);

        return $return;
    }
public function validate($value)
    {
        //Use string's validator
        $return = parent::validate($value);

        //Apply additional rules
        if ($return->status === true && (preg_match(
            '/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/',
            $value,
            $matches
        ))) {
            if (checkdate($matches[2], $matches[3], $matches[1])) {
                $timestamp = strtotime($value);

                //validate formatMinimum
                if ($this->formatMinimum !== null
                    && $timestamp < strtotime($this->formatMinimum)
                ) {
                    $failure = 'formatMinimum';
                    goto error;
                }

                //validate formatMaximum
                if ($this->formatMaximum !== null
                    && $timestamp > strtotime($this->formatMaximum)
                ) {
                    $failure = 'formatMaximum';
                    goto error;
                }

                //Set status to success
                $return->status = true;

                return $return;
            }
        }

        $failure = 'failure';

        error:
        $return->status = false;
        $return->errorObject = new IncorrectParametersException([
            [
                'type' => static::getType(),
                'failure' => $failure
            ]
        ]);

        return $return;
    }
public function validate ( $ value ) { //Use string's validator $ return = parent :: validate ( $ value ) ; //Apply additional rules if ( $ return -> status === true && ( preg_match ( '/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/' , $ value , $ matches ) ) ) { if ( checkdate ( $ matches [ 2 ] , $ matches [ 3 ] , $ matches [ 1 ] ) ) { $ timestamp = strtotime ( $ value ) ; //validate formatMinimum if ( $ this -> formatMinimum !== null && $ timestamp < strtotime ( $ this -> formatMinimum ) ) { $ failure = 'formatMinimum' ; goto error ; } //validate formatMaximum if ( $ this -> formatMaximum !== null && $ timestamp > strtotime ( $ this -> formatMaximum ) ) { $ failure = 'formatMaximum' ; goto error ; } //Set status to success $ return -> status = true ; return $ return ; } } $ failure = 'failure' ; error : $ return -> status = false ; $ return -> errorObject = new IncorrectParametersException ( [ [ 'type' => static :: getType ( ) , 'failure' => $ failure ] ] ) ; return $ return ; }
Validate value, validates as SQL date or SQL datetime
@see \Phramework\Validate\ValidateResult for ValidateResult object
@see https://dev.mysql.com/doc/refman/5.1/en/datetime.html
@param  mixed $value Value to validate
@return ValidateResult
@todo set errorObject
Validate value validates as SQL date or SQL datetime