Assert\Assertion::date PHP Метод

date() публичный статический Метод

Assert that date is valid and corresponds to the given format.
public static date ( string $value, string $format, string | null $message = null, string | null $propertyPath = null ) : boolean
$value string
$format string supports all of the options date(), except for the following: N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r.
$message string | null
$propertyPath string | null
Результат boolean
    public static function date($value, $format, $message = null, $propertyPath = null)
    {
        static::string($value, $message, $propertyPath);
        static::string($format, $message, $propertyPath);
        $dateTime = \DateTime::createFromFormat($format, $value);
        if (false === $dateTime || $value !== $dateTime->format($format)) {
            $message = sprintf($message ?: 'Date "%s" is invalid or does not match format "%s".', static::stringify($value), static::stringify($format));
            throw static::createException($value, $message, static::INVALID_DATE, $propertyPath, array('format' => $format));
        }
        return true;
    }

Usage Example

 protected function guardRequiredState()
 {
     parent::guardRequiredState();
     Assertion::notNull($this->auth_token);
     Assertion::date($this->token_expire_date, DATE_ISO8601);
 }
All Usage Examples Of Assert\Assertion::date