DateIntervalToStringTransformer

class DateIntervalToStringTransformer implements DataTransformerInterface

Transforms between a date string and a DateInterval object.

Methods

__construct(string $format = 'P%yY%mM%dDT%hH%iM%sS', bool $parseSigned = false)

Transforms a \DateInterval instance to a string.

mixed transform(mixed $value)

Transforms a DateInterval object into a date string with the configured format.

mixed reverseTransform(mixed $value)

Transforms a date string in the configured format into a DateInterval object.

Details

__construct(string $format = 'P%yY%mM%dDT%hH%iM%sS', bool $parseSigned = false)

Transforms a \DateInterval instance to a string.

Parameters

string $format The date format
bool $parseSigned Whether to parse as a signed interval

See also

\DateInterval::format() for supported formats

mixed transform(mixed $value)

Transforms a DateInterval object into a date string with the configured format.

Parameters

mixed $value The value in the original representation

Return Value

mixed The value in the transformed representation

Exceptions

UnexpectedTypeException If the given value is not a \DateInterval instance.

mixed reverseTransform(mixed $value)

Transforms a date string in the configured format into a DateInterval object.

Parameters

mixed $value The value in the transformed representation

Return Value

mixed The value in the original representation

Exceptions

UnexpectedTypeException If the given value is not a string.
TransformationFailedException If the date interval could not be parsed.