‪TYPO3CMS  ‪main
TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter Class Reference
Inheritance diagram for TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter:
TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter TYPO3\CMS\Extbase\Property\TypeConverterInterface TYPO3\CMS\Core\SingletonInterface

Public Member Functions

DateTime TYPO3 CMS Extbase Error Error null convertFrom ($source, string $targetType, array $convertedChildProperties=[], PropertyMappingConfigurationInterface $configuration=null)
 
- ‪Public Member Functions inherited from ‪TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter
 getTargetTypeForSource ($source, string $originalTargetType, PropertyMappingConfigurationInterface $configuration=null)
 
 getSourceChildPropertiesToBeConverted ($source)
 
 getTypeOfChildProperty (string $targetType, string $propertyName, PropertyMappingConfigurationInterface $configuration)
 

Public Attributes

const CONFIGURATION_DATE_FORMAT = 'dateFormat'
 
const DEFAULT_DATE_FORMAT = \DateTimeInterface::W3C
 

Protected Member Functions

 isDatePartKeysProvided (array $source)
 
 getDefaultDateFormat (PropertyMappingConfigurationInterface $configuration=null)
 
 overrideTimeIfSpecified (\DateTime $date, array $source)
 

Detailed Description

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' => '<hour>', // integer 'minute' => '<minute>', // integer 'seconds' => '<seconds>', // integer 'timezone' => '<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' => '<day>', // integer 'month' => '<month>', // integer 'year' => '<year>', // integer );

Definition at line 63 of file DateTimeConverter.php.

Member Function Documentation

◆ convertFrom()

DateTime TYPO3 CMS Extbase Error Error null TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::convertFrom (   $source,
string  $targetType,
array  $convertedChildProperties = [],
PropertyMappingConfigurationInterface  $configuration = null 
)

Converts $source to a \DateTime using the configured dateFormat

Parameters
string | int | array$source‪the string to be converted to a \DateTime object
string$targetType‪must be "DateTime"
array$convertedChildProperties‪not used currently
\TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface$configuration
Returns
‪\DateTime|\TYPO3\CMS\Extbase\Error\Error|null
Exceptions

Implements TYPO3\CMS\Extbase\Property\TypeConverterInterface.

Definition at line 89 of file DateTimeConverter.php.

References TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter\getDefaultDateFormat(), TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter\isDatePartKeysProvided(), and TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter\overrideTimeIfSpecified().

◆ getDefaultDateFormat()

TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::getDefaultDateFormat ( PropertyMappingConfigurationInterface  $configuration = null)
protected

Determines the default date format to use for the conversion. If no format is specified in the mapping configuration DEFAULT_DATE_FORMAT is used.

Exceptions

Definition at line 155 of file DateTimeConverter.php.

References TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter\DEFAULT_DATE_FORMAT.

Referenced by TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter\convertFrom().

◆ isDatePartKeysProvided()

TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::isDatePartKeysProvided ( array  $source)
protected

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

Definition at line 142 of file DateTimeConverter.php.

Referenced by TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter\convertFrom().

◆ overrideTimeIfSpecified()

TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::overrideTimeIfSpecified ( \DateTime  $date,
array  $source 
)
protected

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

Definition at line 174 of file DateTimeConverter.php.

Referenced by TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter\convertFrom().

Member Data Documentation

◆ CONFIGURATION_DATE_FORMAT

const TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT = 'dateFormat'

◆ DEFAULT_DATE_FORMAT