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
 
Properties
- $priority : int
 - The priority for this converter.
 - $sourceTypes : array<string|int, string>
 - The source types this converter can convert.
 - $targetType : string
 - The target type this converter can convert to.
 
Methods
- canConvertFrom() : bool
 - If conversion is possible.
 - convertFrom() : DateTime|Error|null
 - Converts $source to a \DateTime using the configured dateFormat
 - getPriority() : int
 - Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
 - getSourceChildPropertiesToBeConverted() : array<string|int, mixed>
 - Return a list of sub-properties inside the source object.
 - getSupportedSourceTypes() : array<string|int, string>
 - Returns the list of source types the TypeConverter can handle.
 - getSupportedTargetType() : string
 - Return the target type this TypeConverter converts to.
 - 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
 
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
    
    
    
    
Properties
$priority
The priority for this converter.
will be removed in TYPO3 v13.0, as this is defined in Services.yaml.
        protected
            int
    $priority
     = 10
    
    
    
    
    
$sourceTypes
The source types this converter can convert.
will be removed in TYPO3 v13.0, as this is defined in Services.yaml.
        protected
            array<string|int, string>
    $sourceTypes
     = ['string', 'integer', 'array']
    
    
    
    
    
$targetType
The target type this converter can convert to.
will be removed in TYPO3 v13.0, as this is defined in Services.yaml.
        protected
            string
    $targetType
     = \DateTime::class
    
    
    
    
    
Methods
canConvertFrom()
If conversion is possible.
    public
                    canConvertFrom(string|array<string|int, mixed>|int $source, string $targetType) : bool
    Parameters
- $source : string|array<string|int, mixed>|int
 - $targetType : string
 
only to be used within Extbase, not part of TYPO3 Core API.
Return values
boolconvertFrom()
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 $configuration = null ]) : DateTime|Error|null
    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
 
only to be used within Extbase, not part of TYPO3 Core API.
Tags
Return values
DateTime|Error|nullgetPriority()
Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
    public
                    getPriority() : int
    will be removed in TYPO3 v13.0, as this is defined in Services.yaml.
Return values
intgetSourceChildPropertiesToBeConverted()
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>getSupportedSourceTypes()
Returns the list of source types the TypeConverter can handle.
    public
                    getSupportedSourceTypes() : array<string|int, string>
    will be removed in TYPO3 v13.0, as this is defined in Services.yaml.
Must be PHP simple types, classes or object is not allowed.
Return values
array<string|int, string>getSupportedTargetType()
Return the target type this TypeConverter converts to.
    public
                    getSupportedTargetType() : string
    will be removed in TYPO3 v13.0, as this is defined in Services.yaml.
Can be a simple type or a class name.
Return values
stringgetTargetTypeForSource()
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>