class DateTimeConverter extends AbstractTypeConverter (View source)

Converter which transforms from string, integer and array into DateTime objects.

For integers the default is to treat them as a unix timestamp. If a format to cerate from is given, this will be used instead.

If source is a string it is expected to be formatted according to DEFAULT_DATE_FORMAT. This default date format can be overridden in the initialize*Action() method like this::

$this->arguments[''] ->getPropertyMappingConfiguration() ->forProperty('') // this line can be skipped in order to specify the format for all properties ->setTypeConverterOption(\Neos\Flow\Property\TypeConverter\DateTimeConverter::class, \Neos\Flow\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT, '');

If the source is of type array, it is possible to override the format in the source::

array( 'date' => '', 'dateFormat' => '' );

By using an array as source you can also override time and timezone of the created DateTime object::

array( 'date' => '', '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 );

Constants

CONFIGURATION_DATE_FORMAT

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 http://www.w3.org/TR/NOTE-datetime.html

Properties

protected string[] $sourceTypes
protected string $targetType
protected int $priority

Methods

string[]
getSupportedSourceTypes()

Returns the list of source types the TypeConverter can handle.

string
getSupportedTargetType()

Return the target type this TypeConverter converts to.

string
getTargetTypeForSource(mixed $source, string $originalTargetType, PropertyMappingConfigurationInterface $configuration = null)

Returns the $originalTargetType unchanged in this implementation.

int
getPriority()

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

bool
canConvertFrom(mixed $source, string $targetType)

If conversion is possible.

array
getSourceChildPropertiesToBeConverted(mixed $source)

Returns an empty list of sub property names

string|null
getTypeOfChildProperty(string $targetType, string $propertyName, PropertyMappingConfigurationInterface $configuration)

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

mixed|null|Error
convertFrom(mixed $source, string $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)

Converts $source to a \DateTime using the configured dateFormat

bool
isDatePartKeysProvided(array $source)

Returns whether date information (day, month, year) are present as keys in $source.

string
getDefaultDateFormat(PropertyMappingConfigurationInterface $configuration = null)

Determines the default date format to use for the conversion.

overrideTime(DateTimeInterface $date, array $source)

Overrides hour, minute & second of the given date with the values in the $source array

Details

string[] getSupportedSourceTypes()

Returns the list of source types the TypeConverter can handle.

Must be PHP simple types, classes or object is not allowed.

Return Value

string[]

string getSupportedTargetType()

Return the target type this TypeConverter converts to.

Can be a simple type or a class name.

Return Value

string

string getTargetTypeForSource(mixed $source, string $originalTargetType, PropertyMappingConfigurationInterface $configuration = null)

Returns the $originalTargetType unchanged in this implementation.

Parameters

mixed $source

the source data

string $originalTargetType

the type we originally want to convert to

PropertyMappingConfigurationInterface $configuration

Return Value

string

int getPriority()

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

Return Value

int

bool canConvertFrom(mixed $source, string $targetType)

If conversion is possible.

Parameters

mixed $source

the source data

string $targetType

the type to convert to.

Return Value

bool

true if this TypeConverter can convert from $source to $targetType, false otherwise.

array getSourceChildPropertiesToBeConverted(mixed $source)

Returns an empty list of sub property names

Parameters

mixed $source

Return Value

array

string|null getTypeOfChildProperty(string $targetType, string $propertyName, PropertyMappingConfigurationInterface $configuration)

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

Parameters

string $targetType
string $propertyName
PropertyMappingConfigurationInterface $configuration

Return Value

string|null

the type of $propertyName in $targetType

mixed|null|Error convertFrom(mixed $source, string $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)

Converts $source to a \DateTime using the configured dateFormat

Parameters

mixed $source
string $targetType
array $convertedChildProperties
PropertyMappingConfigurationInterface $configuration

Return Value

mixed|null|Error

the target type, or an error object if a user-error occurred

Exceptions

InvalidPropertyMappingConfigurationException
TypeConverterException

protected bool isDatePartKeysProvided(array $source)

Returns whether date information (day, month, year) are present as keys in $source.

Parameters

array $source

Return Value

bool

protected string getDefaultDateFormat(PropertyMappingConfigurationInterface $configuration = null)

Determines the default date format to use for the conversion.

If no format is specified in the mapping configuration DEFAULT_DATE_FORMAT is used.

Parameters

PropertyMappingConfigurationInterface $configuration

Return Value

string

Exceptions

InvalidPropertyMappingConfigurationException

protected DateTimeInterface overrideTime(DateTimeInterface $date, array $source)

Overrides hour, minute & second of the given date with the values in the $source array

Parameters

DateTimeInterface $date
array $source

Return Value

DateTimeInterface