2 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
102 if (!is_callable(array(
$targetType,
'createFromFormat'))) {
105 if (is_array($source)) {
108 if (is_integer($source)) {
111 return is_string($source);
127 if (is_string($source)) {
128 $dateAsString = $source;
129 }
elseif (is_integer($source)) {
130 $dateAsString = strval($source);
132 if (isset($source[
'date']) && is_string($source[
'date'])) {
133 $dateAsString = $source[
'date'];
134 }
elseif (isset($source[
'date']) && is_integer($source[
'date'])) {
135 $dateAsString = strval($source[
'date']);
137 if ($source[
'day'] < 1 || $source[
'month'] < 1 || $source[
'year'] < 1) {
138 return new \TYPO3\CMS\Extbase\Error\Error(
'Could not convert the given date parts into a DateTime object because one or more parts were 0.', 1333032779);
140 $dateAsString = sprintf(
'%d-%d-%d', $source[
'year'], $source[
'month'], $source[
'day']);
142 throw new \TYPO3\CMS\Extbase\Property\Exception\TypeConverterException(
'Could not convert the given source into a DateTime object because it was not an array with a valid date as a string', 1308003914);
144 if (isset($source[
'dateFormat']) && $source[
'dateFormat'] !==
'') {
145 $dateFormat = $source[
'dateFormat'];
148 if ($dateAsString ===
'') {
151 if (ctype_digit($dateAsString) && $configuration === null && (!is_array($source) || !isset($source[
'dateFormat']))) {
154 if (is_array($source) && isset($source[
'timezone']) && (
string)$source[
'timezone'] !==
'') {
156 $timezone = new \DateTimeZone($source[
'timezone']);
158 throw new \TYPO3\CMS\Extbase\Property\Exception\TypeConverterException(
'The specified timezone "' . $source[
'timezone'] .
'" is invalid.', 1308240974);
160 $date = $targetType::createFromFormat($dateFormat, $dateAsString, $timezone);
162 $date = $targetType::createFromFormat($dateFormat, $dateAsString);
164 if ($date ===
false) {
165 return new \TYPO3\CMS\Extbase\Validation\Error(
'The date "%s" was not recognized (for format "%s").', 1307719788, array($dateAsString, $dateFormat));
167 if (is_array($source)) {
181 return isset($source[
'day']) && ctype_digit($source[
'day'])
182 && isset($source[
'month']) && ctype_digit($source[
'month'])
183 && isset($source[
'year']) && ctype_digit($source[
'year']);
196 if ($configuration === null) {
197 return self::DEFAULT_DATE_FORMAT;
199 $dateFormat = $configuration->getConfigurationValue(\TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::class, self::CONFIGURATION_DATE_FORMAT);
200 if ($dateFormat === null) {
201 return self::DEFAULT_DATE_FORMAT;
202 }
elseif ($dateFormat !== null && !is_string($dateFormat)) {
203 throw new \TYPO3\CMS\Extbase\Property\Exception\InvalidPropertyMappingConfigurationException(
'CONFIGURATION_DATE_FORMAT must be of type string, "' . (is_object($dateFormat) ? get_class($dateFormat) : gettype($dateFormat)) .
'" given', 1307719569);
217 if (!isset($source[
'hour']) && !isset($source[
'minute']) && !isset($source[
'second'])) {
220 $hour = isset($source[
'hour']) ? (int)$source[
'hour'] : 0;
221 $minute = isset($source[
'minute']) ? (int)$source[
'minute'] : 0;
222 $second = isset($source[
'second']) ? (int)$source[
'second'] : 0;
223 $date->setTime($hour, $minute, $second);