Validates that a given value is a DateTime instance or can be converted into one.

package Default
inherited_from \Zend\Validator\Date

 Methods

Set default options for this instance

__construct(array $options = array()
inherited_from \Zend\Validator\Date::__construct()

Parameters

$options

array

Abstract constructor for all validators A validator should accept following parameters: - nothing f.e. Validator() - one or multiple scalar values f.e. Validator($first, $second, $third) - an array f.e. Validator(array($first => 'first', $second => 'second', $third => 'third')) - an instance of Traversable f.e. Validator($config_instance)

__construct(array|\Traversable $options = null
Inherited

Parameters

$options

array\Traversable

Magic function returns the value of the requested property, if and only if it is the value or a message variable.

__get(string $property) : mixed
Inherited

Parameters

$property

string

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

mixed

Invoke as command

__invoke(mixed $value) : boolean
Inherited

Parameters

$value

mixed

Returns

boolean

Returns the base value from which the step should be computed

getBaseValue() : string | integer | \DateTime

Returns

stringinteger\DateTime

Get default translation object for all validate objects

getDefaultTranslator() : \Zend\Validator\Translator\TranslatorInterface | null
InheritedStatic

Returns

\Zend\Validator\Translator\TranslatorInterfacenull

Get default translation text domain for all validate objects

getDefaultTranslatorTextDomain() : string
InheritedStatic

Returns

string

Returns the format option

getFormat() : string | null
Inherited

Returns

stringnull

Returns the maximum allowed message length

getMessageLength() : integer
InheritedStatic

Returns

integer

Returns the message templates from the validator

getMessageTemplates() : array
Inherited

Returns

array

Returns an array of the names of variables that are used in constructing validation failure messages

getMessageVariables() : array
Inherited

Returns

array

Returns array of validation failure messages

getMessages() : array
Inherited

If isValid() was never called or if the most recent isValid() call returned true, then this method returns an empty array.

inherited_from \Zend\Validator\ValidatorInterface::getMessages()

Returns

array

Returns an option

getOption(string $option) : mixed
Inherited

Parameters

$option

string

Option to be returned

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

mixedReturned option

Returns all available options

getOptions() : array
Inherited

Returns

arrayArray with all available options

Returns the step date interval

getStep() : \DateInterval

Returns

\DateInterval

Returns the timezone option

getTimezone() : \DateTimeZone

Returns

\DateTimeZone

Return translation object

getTranslator() : \Zend\Validator\Translator\TranslatorInterface | null
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::getTranslator()

Returns

\Zend\Validator\Translator\TranslatorInterfacenull

Return the translation text domain

getTranslatorTextDomain() : string
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::getTranslatorTextDomain()

Returns

string

Is there a default translation object set?

hasDefaultTranslator() : boolean
InheritedStatic

Returns

boolean

Does this validator have its own specific translator?

hasTranslator() : boolean
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::hasTranslator()

Returns

boolean

Is translation enabled?

isTranslatorEnabled() : boolean
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::isTranslatorEnabled()

Returns

boolean

Returns true if a date is within a valid step

isValid(string|integer|\DateTime $value) : boolean
inherited_from \Zend\Validator\Date::isValid()

Parameters

$value

stringinteger\DateTime

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

boolean

Returns true if $value is a DateTime instance or can be converted into one.

isValid(string|array|integer|\DateTime $value) : boolean
Inherited

Parameters

$value

stringarrayinteger\DateTime

Returns

boolean

Retrieve flag indicating whether or not value should be obfuscated in messages

isValueObscured() : boolean
Inherited

Returns

boolean

Sets the base value from which the step should be computed

setBaseValue(string|integer|\DateTime $baseValue) : \Zend\Validator\DateStep

Parameters

$baseValue

stringinteger\DateTime

Returns

\Zend\Validator\DateStep

Set default translation object for all validate objects

setDefaultTranslator(\Zend\Validator\Translator\TranslatorInterface|null $translator = null, string $textDomain = null) : void
InheritedStatic

Parameters

$translator

\Zend\Validator\Translator\TranslatorInterfacenull

$textDomain

string

(optional)

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Set default translation text domain for all validate objects

setDefaultTranslatorTextDomain(string $textDomain = 'default') : void
InheritedStatic

Parameters

$textDomain

string

Sets the format option

setFormat(string $format = self::FORMAT_DEFAULT) : \Zend\Validator\Date
Inherited

Format cannot be null. It will always default to 'Y-m-d', even if null is provided.

todo validate the format

Parameters

$format

string

Returns

\Zend\Validator\Dateprovides a fluent interface

Sets the validation failure message template for a particular key

setMessage(string $messageString, string $messageKey = null) : \Zend\Validator\AbstractValidator
Inherited

Parameters

$messageString

string

$messageKey

string

OPTIONAL

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

\Zend\Validator\AbstractValidatorProvides a fluent interface

Sets the maximum allowed message length

setMessageLength(integer $length = -1
InheritedStatic

Parameters

$length

integer

Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.

setMessages(array $messages) : \Zend\Validator\AbstractValidator
Inherited

Parameters

$messages

array

Returns

\Zend\Validator\AbstractValidator

Sets one or multiple options

setOptions(array|\Traversable $options = array()) : \Zend\Validator\AbstractValidator
Inherited

Parameters

$options

array\Traversable

Options to set

Exceptions

\Zend\Validator\Exception\InvalidArgumentException If $options is not an array or Traversable

Returns

\Zend\Validator\AbstractValidatorProvides fluid interface

Sets the step date interval

setStep(\DateInterval $step) : \Zend\Validator\DateStep

Parameters

$step

\DateInterval

Returns

\Zend\Validator\DateStep

Sets the timezone option

setTimezone(\DateTimeZone $timezone) : \Zend\Validator\DateStep

Parameters

$timezone

\DateTimeZone

Returns

\Zend\Validator\DateStep

Set translation object

setTranslator(\Zend\Validator\Translator\TranslatorInterface|null $translator = null, string $textDomain = null) : \Zend\Validator\AbstractValidator
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::setTranslator()

Parameters

$translator

\Zend\Validator\Translator\TranslatorInterfacenull

$textDomain

string

(optional)

Exceptions

\Zend\Validator\Exception\InvalidArgumentException

Returns

\Zend\Validator\AbstractValidator

Indicate whether or not translation should be enabled

setTranslatorEnabled(boolean $flag = true) : \Zend\Validator\AbstractValidator
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::setTranslatorEnabled()

Parameters

$flag

boolean

Returns

\Zend\Validator\AbstractValidator

Set translation text domain

setTranslatorTextDomain(string $textDomain = 'default') : \Zend\Validator\AbstractValidator
Inherited
inherited_from \Zend\Validator\Translator\TranslatorAwareInterface::setTranslatorTextDomain()

Parameters

$textDomain

string

Returns

\Zend\Validator\AbstractValidator

Set flag indicating whether or not value should be obfuscated in messages

setValueObscured(boolean $flag) : \Zend\Validator\AbstractValidator
Inherited

Parameters

$flag

boolean

Returns

\Zend\Validator\AbstractValidator

Implodes the array into a string and proxies to {@link convertString()}.

convertArray(array $value, boolean $addErrors = true) : boolean | \DateTime
Inherited
todo enhance the implosion

Parameters

$value

array

$addErrors

boolean

Returns

boolean\DateTime

Attempts to convert an double into a DateTime object

convertDouble(double $value) : boolean | \DateTime
Inherited

Parameters

$value

double

Returns

boolean\DateTime

Attempts to convert an integer into a DateTime object

convertInteger(integer $value) : boolean | \DateTime
Inherited

Parameters

$value

integer

Returns

boolean\DateTime

Supports formats with ISO week (W) definitions

convertString(string $value, boolean $addErrors = true
see
inherited_from \Zend\Validator\Date::convertString()

Parameters

$value

$addErrors

Attempts to convert a string into a DateTime object

convertString(string $value, boolean $addErrors = true) : boolean | \DateTime
Inherited

Parameters

$value

string

$addErrors

boolean

Returns

boolean\DateTime

Attempts to convert an int, string, or array to a DateTime object

convertToDateTime(string|integer|array $param, boolean $addErrors = true) : boolean | \DateTime
Inherited

Parameters

$param

stringintegerarray

$addErrors

boolean

Returns

boolean\DateTime

Constructs and returns a validation failure message with the given message key and value.

createMessage(string $messageKey, string|array|object $value) : string
Inherited

Returns null if and only if $messageKey does not correspond to an existing template.

If a translator is available and a translation exists for $messageKey, the translation will be used.

Parameters

$messageKey

string

$value

stringarrayobject

Returns

string

error()

error(string $messageKey, string $value = null) : void
Inherited

Parameters

$messageKey

string

$value

string

OPTIONAL

Returns the validation value

getValue() : mixed
Inherited

Returns

mixedValue to be validated

Sets the value to be validated and clears the messages and errors arrays

setValue(mixed $value) : void
Inherited

Parameters

$value

mixed

Translate a validation message

translateMessage(string $messageKey, string $message) : string
Inherited

Parameters

$messageKey

string

$message

string

Returns

string

Get lower bound of difference in secondss Converts a given `$diffParts` array into seconds

computeDiffMinSeconds(array<mixed,integer> $diffParts) : integer

Parameters

$diffParts

array<mixed,integer>

Returns

integer

Get upper bound of the given interval in seconds Converts a given `$intervalParts` array into seconds

computeIntervalMaxSeconds(array<mixed,integer> $intervalParts) : integer

Parameters

$intervalParts

array<mixed,integer>

Returns

integer

computeMinStepAndRequiredIterations()

computeMinStepAndRequiredIterations(array<mixed,integer> $intervalParts, array<mixed,integer> $diffParts) : array<mixed,integer>

Parameters

$intervalParts

array<mixed,integer>

$diffParts

array<mixed,integer>

Returns

array<mixed,integer>(ordered tuple containing minimum steps and required step iterations

Multiply the step interval by the lower bound of steps to reach the target

computeMinSteps(array<mixed,integer> $intervalParts, array<mixed,integer> $diffParts) : integer

Parameters

$intervalParts

array<mixed,integer>

$diffParts

array<mixed,integer>

Returns

integer

Computes minimum interval to use for iterations while checking steps

computeMinimumInterval(array<mixed,integer> $intervalParts, integer $minSteps) : \DateInterval

Parameters

$intervalParts

array<mixed,integer>

$minSteps

integer

Returns

\DateInterval

Fall back to slower (but accurate) method for complex intervals.

fallbackIncrementalIterationLogic(\DateTime $baseDate, \DateTime $valueDate, array<mixed,integer> $intervalParts, array<mixed,integer> $diffParts, \DateInterval $step) : boolean

Keep adding steps to the base date until a match is found or until the value is exceeded.

This is really slow if the interval is small, especially if the default base date of 1/1/1970 is used. We can skip a chunk of iterations by starting at the lower bound of steps needed to reach the target

Parameters

$baseDate

\DateTime

$valueDate

\DateTime

$intervalParts

array<mixed,integer>

$diffParts

array<mixed,integer>

$step

\DateInterval

Returns

boolean

 Properties

 

$abstractOptions

$abstractOptions 

Default

array('messages' => array(), 'messageTemplates' => array(), 'messageVariables' => array(), 'translator' => null, 'translatorTextDomain' => null, 'translatorEnabled' => true, 'valueObscured' => false)
 

Optional base date value

$baseValue : string | integer | \DateTime

Default

'1970-01-01T00:00:00Z'
 

Default translation object for all validate objects

$defaultTranslator : \Zend\Validator\Translator\TranslatorInterface

Default

Static
 

Default text domain to be used with translator

$defaultTranslatorTextDomain : string

Default

'default'
Static
 

$format

$format : string

Default

self::FORMAT_DEFAULT
 

Limits the maximum returned length of an error message

$messageLength : integer

Default

-1
Static
 

Validation failure message template definitions

$messageTemplates : array

Default

array(self::INVALID => "Invalid type given. String, integer, array or DateTime expected", self::INVALID_DATE => "The input does not appear to be a valid date", self::FALSEFORMAT => "The input does not fit the date format '%format%'", self::NOT_STEP => "The input is not a valid step")
inherited_from \Zend\Validator\Date::messageTemplates
 

Validation failure message template definitions

$messageTemplates : array

Default

array(self::INVALID => "Invalid type given. String, integer, array or DateTime expected", self::INVALID_DATE => "The input does not appear to be a valid date", self::FALSEFORMAT => "The input does not fit the date format '%format%'")
 

$messageVariables

$messageVariables : array

Default

array('format' => 'format')
 

Date step interval (defaults to 1 day).

$step : \DateInterval

Default

Uses the DateInterval specification.

 

Optional timezone to be used when the baseValue and validation values do not contain timezone info

$timezone : \DateTimeZone

Default

 

The value to be validated

$value : mixed

Default

 Constants

 

FALSEFORMAT

FALSEFORMAT = 'dateFalseFormat' 
 

Default format constant

FORMAT_DEFAULT = \DateTime::ISO8601 
inherited_from \Zend\Validator\Date::FORMAT_DEFAULT
 

Default format constant

FORMAT_DEFAULT = 'Y-m-d' : string
 

INVALID

INVALID = 'dateInvalid' 
 

INVALID_DATE

INVALID_DATE = 'dateInvalidDate' 
 

NOT_STEP

NOT_STEP = 'dateStepNotStep'