TYPO3  7.6
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
DateTimeConverter Class Reference
Inheritance diagram for DateTimeConverter:
AbstractTypeConverter TypeConverterInterface SingletonInterface

Public Member Functions

 canConvertFrom ($source, $targetType)
 
 convertFrom ($source, $targetType, array $convertedChildProperties=array(),\TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration=null)
 
- Public Member Functions inherited from AbstractTypeConverter
 injectObjectManager (\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
 
 getSupportedSourceTypes ()
 
 getSupportedTargetType ()
 
 getTargetTypeForSource ($source, $originalTargetType,\TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration=null)
 
 getPriority ()
 
 canConvertFrom ($source, $targetType)
 
 getSourceChildPropertiesToBeConverted ($source)
 
 getTypeOfChildProperty ($targetType, $propertyName,\TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration)
 
- Public Member Functions inherited from TypeConverterInterface
 getTargetTypeForSource ($source, $originalTargetType, PropertyMappingConfigurationInterface $configuration=null)
 

Public Attributes

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

Protected Member Functions

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

Protected Attributes

 $sourceTypes = array('string', 'integer', 'array')
 
 $targetType = 'DateTime'
 
 $priority = 1
 
- Protected Attributes inherited from AbstractTypeConverter
 $sourceTypes = array()
 
 $targetType = ''
 
 $priority
 
 $objectManager
 

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(::class, ::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

canConvertFrom (   $source,
  $targetType 
)

If conversion is possible.

Parameters
string$source
string$targetType
Returns
bool

Implements TypeConverterInterface.

Definition at line 100 of file DateTimeConverter.php.

References DateTimeConverter\$targetType.

convertFrom (   $source,
  $targetType,
array  $convertedChildProperties = array(),
\TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface  $configuration = null 
)

Converts $source to a using the configured dateFormat

Parameters
string | int | array$sourcethe string to be converted to a object
string$targetTypemust be "DateTime"
array$convertedChildPropertiesnot used currently
\TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface$configuration
Returns
Exceptions
\TYPO3\CMS\Extbase\Property\Exception\TypeConverterException

Implements TypeConverterInterface.

Definition at line 124 of file DateTimeConverter.php.

References elseif, DateTimeConverter\getDefaultDateFormat(), DateTimeConverter\isDatePartKeysProvided(), and DateTimeConverter\overrideTimeIfSpecified().

getDefaultDateFormat ( \TYPO3\CMS\Extbase\Property\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.

Parameters
\TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface$configuration
Returns
string
Exceptions
\TYPO3\CMS\Extbase\Property\Exception\InvalidPropertyMappingConfigurationException

Definition at line 194 of file DateTimeConverter.php.

References elseif.

Referenced by DateTimeConverter\convertFrom().

isDatePartKeysProvided ( array  $source)
protected

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

Parameters
array$source
Returns
bool

Definition at line 179 of file DateTimeConverter.php.

Referenced by DateTimeConverter\convertFrom().

overrideTimeIfSpecified ( \DateTime  $date,
array  $source 
)
protected

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

Parameters
\DateTime$date
array$source
Returns
void

Definition at line 215 of file DateTimeConverter.php.

Referenced by DateTimeConverter\convertFrom().

Member Data Documentation

$priority = 1
protected

Definition at line 91 of file DateTimeConverter.php.

$sourceTypes = array('string', 'integer', 'array')
protected

Definition at line 81 of file DateTimeConverter.php.

$targetType = 'DateTime'
protected

Definition at line 86 of file DateTimeConverter.php.

Referenced by DateTimeConverter\canConvertFrom().

const CONFIGURATION_DATE_FORMAT = 'dateFormat'

Definition at line 68 of file DateTimeConverter.php.

const DEFAULT_DATE_FORMAT = \DateTime::W3C

Definition at line 76 of file DateTimeConverter.php.