local = (bool) $local; } /** * Is the date and time valid? * * @param string|DateTime $value * @param mixed $context * * @return bool * * @see \Zend_Validate_Interface::isValid() */ public function isValid($value, $context = null) { if (! $value instanceof DateTime && ! is_string($value)) { $this->_error(t('Invalid type given. Instance of DateTime or date/time string expected')); return false; } if (is_string($value)) { $format = $this->local === true ? 'Y-m-d\TH:i:s' : DateTime::RFC3339; $dateTime = DateTime::createFromFormat($format, $value); if ($dateTime === false || $dateTime->format($format) !== $value) { $this->_error(sprintf(t('Date/time string not in the expected format %s'), $format)); return false; } } return true; } }