W3cubDocs

/Symfony 4.1

DateIntervalToArrayTransformer

class DateIntervalToArrayTransformer implements DataTransformerInterface

Transforms between a normalized date interval and an interval string/array.

Constants

YEARS
MONTHS
DAYS
HOURS
MINUTES
SECONDS
INVERT

Methods

__construct(array $fields = null, bool $pad = false)
mixed transform(DateInterval $dateInterval)

Transforms a normalized date interval into an interval array.

mixed reverseTransform(mixed $value)

Transforms an interval array into a normalized date interval.

Details

__construct(array $fields = null, bool $pad = false)

Parameters

array $fields The date fields
bool $pad Whether to use padding

mixed transform(DateInterval $dateInterval)

Transforms a normalized date interval into an interval array.

Parameters

DateInterval $dateInterval Normalized date interval

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 an interval array into a normalized date interval.

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 an array
TransformationFailedException if the value could not be transformed