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' => '', // integer 'minute' => '', // integer 'seconds' => '', // integer 'timezone' => '', // string, see http://www.php.net/manual/timezones.php );

As an alternative to providing the date as string, you might supply day, month and year as array items each::

array( 'day' => '', // integer 'month' => '', // integer 'year' => '', // integer );

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

$objectManager  : ObjectManagerInterface
$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>
todo: this method should be abstract or removed, contract is defined by TypeConverterInterface.
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 $originalTargetType unchanged in this implementation.
getTypeOfChildProperty()  : string
todo: this method should be abstract or removed, contract is defined by TypeConverterInterface.
injectObjectManager()  : void
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.

protected int $priority = 10

$sourceTypes

The source types this converter can convert.

protected array<string|int, string> $sourceTypes = ['string', 'integer', 'array']

$targetType

The target type this converter can convert to.

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
Internal

only to be used within Extbase, not part of TYPO3 Core API.

Return values
bool

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 $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
Internal

only to be used within Extbase, not part of TYPO3 Core API.

Tags
throws
TypeConverterException
Return values
DateTime|Error|null

getPriority()

Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.

public getPriority() : int
Return values
int

getSourceChildPropertiesToBeConverted()

todo: this method should be abstract or removed, contract is defined by TypeConverterInterface.

public getSourceChildPropertiesToBeConverted(mixed $source) : array<string|int, mixed>

Returns an empty list of sub property names

Parameters
$source : mixed
Return values
array<string|int, mixed>

getSupportedSourceTypes()

Returns the list of source types the TypeConverter can handle.

public getSupportedSourceTypes() : array<string|int, string>

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

Can be a simple type or a class name.

Return values
string

getTargetTypeForSource()

Returns the $originalTargetType unchanged in this implementation.

public getTargetTypeForSource(mixed $source, string $originalTargetType[, PropertyMappingConfigurationInterface $configuration = null ]) : string
Parameters
$source : mixed

the source data

$originalTargetType : string

the type we originally want to convert to

$configuration : PropertyMappingConfigurationInterface = null
Return values
string

getTypeOfChildProperty()

todo: this method should be abstract or removed, contract is defined by TypeConverterInterface.

public getTypeOfChildProperty(string $targetType, string $propertyName, PropertyMappingConfigurationInterface $configuration) : string

This method is never called, as getSourceChildPropertiesToBeConverted() returns an empty array.

Parameters
$targetType : string
$propertyName : string
$configuration : PropertyMappingConfigurationInterface
Return values
string

isDatePartKeysProvided()

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
bool

overrideTimeIfSpecified()

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
DateTime

        
On this page

Search results