DateTimeToLocalizedStringTransformer
class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
Transforms between a normalized time and a localized time string.
Properties
| static protected | $formats | from BaseDateTimeTransformer | |
| protected | $inputTimezone | from BaseDateTimeTransformer | |
| protected | $outputTimezone | from BaseDateTimeTransformer |
Methods
| __construct(string $inputTimezone = null, string $outputTimezone = null, int $dateFormat = null, int $timeFormat = null, int $calendar = \IntlDateFormatter::GREGORIAN, string $pattern = null) | ||
| mixed | transform(DateTimeInterface $dateTime) Transforms a normalized date into a localized date string/array. | |
| mixed | reverseTransform(mixed $value) Transforms a localized date string/array into a normalized date. | |
| IntlDateFormatter | getIntlDateFormatter(bool $ignoreTimezone = false) Returns a preconfigured IntlDateFormatter instance. | |
| bool | isPatternDateOnly() Checks if the pattern contains only a date. |
Details
__construct(string $inputTimezone = null, string $outputTimezone = null, int $dateFormat = null, int $timeFormat = null, int $calendar = \IntlDateFormatter::GREGORIAN, string $pattern = null)
Parameters
| string | $inputTimezone | The name of the input timezone |
| string | $outputTimezone | The name of the output timezone |
| int | $dateFormat | The date format |
| int | $timeFormat | The time format |
| int | $calendar | One of the \IntlDateFormatter calendar constants |
| string | $pattern | A pattern to pass to \IntlDateFormatter |
Exceptions
| UnexpectedTypeException | If a format is not supported or if a timezone is not a string |
See also
| BaseDateTimeTransformer::formats | for available format options |
mixed transform(DateTimeInterface $dateTime)
Transforms a normalized date into a localized date string/array.
Parameters
| DateTimeInterface | $dateTime | A DateTimeInterface object |
Return Value
| mixed | The value in the transformed representation |
Exceptions
| TransformationFailedException | if the given value is not a \DateTimeInterface or if the date could not be transformed |
mixed reverseTransform(mixed $value)
Transforms a localized date string/array 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 a string, if the date could not be parsed |
protected IntlDateFormatter getIntlDateFormatter(bool $ignoreTimezone = false)
Returns a preconfigured IntlDateFormatter instance.
Parameters
| bool | $ignoreTimezone | Use UTC regardless of the configured timezone |
Return Value
| IntlDateFormatter |
Exceptions
| TransformationFailedException | in case the date formatter can not be constructed |
protected bool isPatternDateOnly()
Checks if the pattern contains only a date.
Return Value
| bool |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.html