DateTimeConverter
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['
If the source is of type array, it is possible to override the format in the source::
array(
'date' => '
By using an array as source you can also override time and timezone of the created DateTime object::
array(
'date' => '
As an alternative to providing the date as string, you might supply day, month and year as array items each::
array(
'day' => '
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
Returns the list of source types the TypeConverter can handle.
Return the target type this TypeConverter converts to.
Returns the $originalTargetType unchanged in this implementation.
Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
If conversion is possible.
Returns an empty list of sub property names
This method is never called, as getSourceChildPropertiesToBeConverted() returns an empty array.
Converts $source to a \DateTime using the configured dateFormat
Returns whether date information (day, month, year) are present as keys in $source.
Determines the default date format to use for the conversion.
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.
string
getSupportedTargetType()
Return the target type this TypeConverter converts to.
Can be a simple type or a class name.
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|Error
convertFrom(mixed $source, string $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
Converts $source to a \DateTime using the configured dateFormat
protected bool
isDatePartKeysProvided(array $source)
Returns whether date information (day, month, year) are present as keys in $source.
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.
protected DateTimeInterface
overrideTime(DateTimeInterface $date, array $source)
Overrides hour, minute & second of the given date with the values in the $source array