W3cubDocs

/Symfony 2.7

Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer

class DateTimeToArrayTransformer extends BaseDateTimeTransformer

Transforms between a normalized time and a localized time string/array.

Methods

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

Constructor.

array transform(DateTime $dateTime)

Transforms a normalized date into a localized date.

DateTime reverseTransform(array $value)

Transforms a localized date into a normalized date.

Details

public __construct(string $inputTimezone = null, string $outputTimezone = null, array $fields = null, bool $pad = false)

Constructor.

Parameters

string $inputTimezone The input timezone
string $outputTimezone The output timezone
array $fields The date fields
bool $pad Whether to use padding

Exceptions

UnexpectedTypeException if a timezone is not a string

public array transform(DateTime $dateTime)

Transforms a normalized date into a localized date.

Parameters

DateTime $dateTime Normalized date.

Return Value

array Localized date.

Exceptions

TransformationFailedException If the given value is not an instance of \DateTime or if the output timezone is not supported.

public DateTime reverseTransform(array $value)

Transforms a localized date into a normalized date.

Parameters

array $value Localized date

Return Value

DateTime Normalized date

Exceptions

TransformationFailedException If the given value is not an array, if the value could not be transformed or if the input timezone is not supported.