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. | ||
mixed | transform(DateTime|DateTimeInterface $dateTime) Transforms a normalized date into a localized date. | |
mixed | reverseTransform(mixed $value) Transforms a localized date into a normalized date. |
Details
__construct(string $inputTimezone = null, string $outputTimezone = null, array $fields = null, bool $pad = false)
Constructor.
Parameters
string | $inputTimezone | The name of the input timezone |
string | $outputTimezone | The name of the output timezone |
array | $fields | The date fields |
bool | $pad | Whether to use padding |
Exceptions
UnexpectedTypeException | if a timezone is not a string |
mixed transform(DateTime|DateTimeInterface $dateTime)
Transforms a normalized date into a localized date.
Parameters
DateTime|DateTimeInterface | $dateTime | A DateTime object |
Return Value
mixed | The value in the transformed representation |
Exceptions
TransformationFailedException | If the given value is not an instance of \DateTime or if the output timezone is not supported. |
mixed reverseTransform(mixed $value)
Transforms a localized date into a normalized date.
Parameters
mixed | $value | The value in the transformed representation |
Return Value
mixed | The value in the original representation |
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. |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/3.0/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.html