DateTimeConverter extends AbstractTypeConverter
Converter which transforms from different input formats into DateTime objects.
Source can be either a string or an array. The date string is expected to be formatted according to DEFAULT_DATE_FORMAT.
But the default date format can be overridden in the initialize*Action() method like this::
$this->arguments['<argumentName>'] ->getPropertyMappingConfiguration() ->forProperty('<propertyName>') // this line can be skipped in order to specify the format for all properties ->setTypeConverterOption(\TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::class, \TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT, '<dateFormat>');
If the source is of type array, it is possible to override the format in the source::
array( 'date' => '<dateString>', 'dateFormat' => '<dateFormat>' );
By using an array as source you can also override time and timezone of the created DateTime object::
array(
'date' => '<dateString>',
'hour' => '
As an alternative to providing the date as string, you might supply day, month and year as array items each::
array(
'day' => '
Table of Contents
Constants
- CONFIGURATION_DATE_FORMAT = 'dateFormat'
- DEFAULT_DATE_FORMAT = \DateTimeInterface::W3C
- The default date format is "YYYY-MM-DDT##:##:##+##:##", for example "2005-08-15T15:52:01+00:00" according to the W3C standard @see http://www.w3.org/TR/NOTE-datetime.html
Methods
- convertFrom() : mixed|Error
- Converts $source to a \DateTime using the configured dateFormat
- getSourceChildPropertiesToBeConverted() : array<string|int, mixed>
- Return a list of sub-properties inside the source object.
- getTargetTypeForSource() : string
- Returns the type for a given source, depending on e.g. the __type setting or other properties.
- getTypeOfChildProperty() : string
- Return the type of a given sub-property inside the $targetType
- getDefaultDateFormat() : string
- Determines the default date format to use for the conversion.
- isDatePartKeysProvided() : bool
- Returns whether date information (day, month, year) are present as keys in $source.
- overrideTimeIfSpecified() : DateTime
- Overrides hour, minute & second of the given date with the values in the $source array
- translateErrorMessage() : string
- Wrap static call to LocalizationUtility to simplify unit testing.
Constants
CONFIGURATION_DATE_FORMAT
public
string
CONFIGURATION_DATE_FORMAT
= 'dateFormat'
DEFAULT_DATE_FORMAT
The default date format is "YYYY-MM-DDT##:##:##+##:##", for example "2005-08-15T15:52:01+00:00" according to the W3C standard @see http://www.w3.org/TR/NOTE-datetime.html
public
string
DEFAULT_DATE_FORMAT
= \DateTimeInterface::W3C
Methods
convertFrom()
Converts $source to a \DateTime using the configured dateFormat
public
convertFrom(string|int|array<string|int, mixed> $source, string $targetType[, array<string|int, mixed> $convertedChildProperties = [] ][, PropertyMappingConfigurationInterface|null $configuration = null ]) : mixed|Error
Parameters
- $source : string|int|array<string|int, mixed>
-
the string to be converted to a \DateTime object
- $targetType : string
-
must be "DateTime"
- $convertedChildProperties : array<string|int, mixed> = []
-
not used currently
- $configuration : PropertyMappingConfigurationInterface|null = null
only to be used within Extbase, not part of TYPO3 Core API.
Tags
Return values
mixed|Error —the target type, or an error object if a user-error occurred
getSourceChildPropertiesToBeConverted()
Return a list of sub-properties inside the source object.
public
getSourceChildPropertiesToBeConverted(mixed $source) : array<string|int, mixed>
Parameters
- $source : mixed
Tags
Return values
array<string|int, mixed>getTargetTypeForSource()
Returns the type for a given source, depending on e.g. the __type setting or other properties.
public
getTargetTypeForSource(mixed $source, string $originalTargetType[, PropertyMappingConfigurationInterface|null $configuration = null ]) : string
Parameters
- $source : mixed
-
the source data
- $originalTargetType : string
-
the type we originally want to convert to
- $configuration : PropertyMappingConfigurationInterface|null = null
Tags
Return values
stringgetTypeOfChildProperty()
Return the type of a given sub-property inside the $targetType
public
getTypeOfChildProperty(string $targetType, string $propertyName, PropertyMappingConfigurationInterface $configuration) : string
Parameters
- $targetType : string
- $propertyName : string
- $configuration : PropertyMappingConfigurationInterface
Tags
Return values
string —the type of $propertyName in $targetType
getDefaultDateFormat()
Determines the default date format to use for the conversion.
protected
getDefaultDateFormat([PropertyMappingConfigurationInterface|null $configuration = null ]) : string
If no format is specified in the mapping configuration DEFAULT_DATE_FORMAT is used.
Parameters
- $configuration : PropertyMappingConfigurationInterface|null = null
Tags
Return values
stringisDatePartKeysProvided()
Returns whether date information (day, month, year) are present as keys in $source.
protected
isDatePartKeysProvided(array<string|int, mixed> $source) : bool
Parameters
- $source : array<string|int, mixed>
Return values
booloverrideTimeIfSpecified()
Overrides hour, minute & second of the given date with the values in the $source array
protected
overrideTimeIfSpecified(DateTime $date, array<string|int, mixed> $source) : DateTime
Parameters
- $date : DateTime
- $source : array<string|int, mixed>
Return values
DateTimetranslateErrorMessage()
Wrap static call to LocalizationUtility to simplify unit testing.
protected
translateErrorMessage(string $translateKey) : string
Parameters
- $translateKey : string