class DateTimeRangeValidator extends AbstractValidator (View source)

Validator for checking Date and Time boundaries

Properties

protected bool $acceptsEmptyValues

Specifies whether this validator accepts empty values.

from  AbstractValidator
protected array $supportedOptions
protected array $options from  AbstractValidator
protected Result[] $resultStack from  AbstractValidator

Methods

__construct(array $options = [])

Constructs the validator and sets validation options

pushResult()

Push a new Result onto the Result stack and return it in order to fix cyclic calls to a single validator.

popResult()

Pop and return the current Result from the stack and make $this->result point to the last Result again.

Result|null
getResult()

Get the current Result for this validation invocation. Use this inside your isValid() implementation to e.g. merge results together into the current one.

validate(mixed $value)

Checks if the given value is valid according to the validator, and returns the Error Messages object which occurred.

void
isValid(mixed $dateTime)

Adds errors if the given DateTime does not match the set boundaries.

void
addError(string $message, int $code, array $arguments = [])

Creates a new validation error object and adds it to $this->errors

array
getOptions()

Returns the options of this validator

bool
isEmpty(mixed $value)

No description

parseReferenceDate(string $referenceDateString)

Calculates a DateTime object from a given Time interval

Details

__construct(array $options = [])

Constructs the validator and sets validation options

Parameters

array $options

Options for the validator

Exceptions

InvalidValidationOptionsException

protected Result pushResult()

Since: Flow 4.3

Push a new Result onto the Result stack and return it in order to fix cyclic calls to a single validator.

protected Result popResult()

Since: Flow 4.3

Pop and return the current Result from the stack and make $this->result point to the last Result again.

Return Value

Result

protected Result|null getResult()

Since: Flow 6.0

Get the current Result for this validation invocation. Use this inside your isValid() implementation to e.g. merge results together into the current one.

Return Value

Result|null

Result validate(mixed $value)

Checks if the given value is valid according to the validator, and returns the Error Messages object which occurred.

Parameters

mixed $value

The value that should be validated

Return Value

Result

Exceptions

InvalidValidationOptionsException

protected void isValid(mixed $dateTime)

Adds errors if the given DateTime does not match the set boundaries.

latestDate and earliestDate may be each

In general, you are able to provide a timestamp or a timestamp with additional calculation. Calculations are done as described in ISO 8601 (2), with an introducing "P". P7MT2H30M for example mean a period of 7 months, 2 hours and 30 minutes (P introduces a period at all, while a following T introduces the time-section of a period. This is not at least in order not to confuse months and minutes, both represented as M). A period is separated from the timestamp with a forward slash "/". If the period follows the timestamp, that period is added to the timestamp; if the period precedes the timestamp, it's subtracted. The timestamp can be one of PHP's supported date formats (1), so also "now" is supported.

Use cases:

If you offer something that has to be manufactured and you ask for a delivery date, you might assure that this date is at least two weeks in advance; this could be done with the expression "now/P2W". If you have a library of ancient goods and want to track a production date that is at least 5 years ago, you can express it with "P5Y/now".

Examples:

If you want to test if a given date is at least five minutes ahead, use earliestDate: now/PT5M If you want to test if a given date was at least 10 days ago, use latestDate: P10D/now If you want to test if a given date is between two fix boundaries, just combine the latestDate and earliestDate-options: earliestDate: 2007-03-01T13:00:00Z latestDate: 2007-03-30T13:00:00Z

Footnotes:

http://de.php.net/manual/en/datetime.formats.compound.php (1) http://en.wikipedia.org/wiki/ISO_8601#Durations (2) http://en.wikipedia.org/wiki/ISO_8601#Time_intervals (3)

Parameters

mixed $dateTime

The DateTime value that should be validated

Return Value

void

protected void addError(string $message, int $code, array $arguments = [])

Creates a new validation error object and adds it to $this->errors

Parameters

string $message

The error message

int $code

The error code (a unix timestamp)

array $arguments

Arguments to be replaced in message

Return Value

void

array getOptions()

Returns the options of this validator

Return Value

array

final protected bool isEmpty(mixed $value)

No description

Parameters

mixed $value

Return Value

bool

true if the given $value is NULL or an empty string ('')

protected DateTime parseReferenceDate(string $referenceDateString)

Calculates a DateTime object from a given Time interval

Parameters

string $referenceDateString

being one of

Return Value

DateTime

Exceptions

InvalidValidationOptionsException

See also

isValid()