[BUGFIX] Native date and datetime values do not consider timezone 67/25367/2
authorOliver Hader <oliver@typo3.org>
Wed, 11 Sep 2013 14:12:20 +0000 (16:12 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Wed, 13 Nov 2013 10:43:51 +0000 (11:43 +0100)
The TCA configuration property "dbType" allows to store "date"
or "datetime" values directly in the database (instead of using
a timestamp value).
However, the timezone is not recognized correctly - besides that,
the serverTimeZone is applied which does not make much sense at
all, since it leaves out DST handling.

Fixes: #51918
Releases: 6.0, 6.1, 6.2
Change-Id: I45da65d8cee2611358303e93305cb5c793223746
Reviewed-on: https://review.typo3.org/25367
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
typo3/sysext/core/Classes/DataHandling/DataHandler.php

index 971c467..4233855 100644 (file)
@@ -780,7 +780,7 @@ class DataHandler {
                                                                if (isset($config['config']['dbType']) && \TYPO3\CMS\Core\Utility\GeneralUtility::inList('date,datetime', $config['config']['dbType'])) {
                                                                        $emptyValue = $dateTimeFormats[$config['config']['dbType']]['empty'];
                                                                        $format = $dateTimeFormats[$config['config']['dbType']]['format'];
-                                                                       $incomingFieldArray[$column] = $incomingFieldArray[$column] ? date($format, $incomingFieldArray[$column]) : $emptyValue;
+                                                                       $incomingFieldArray[$column] = $incomingFieldArray[$column] ? gmdate($format, $incomingFieldArray[$column]) : $emptyValue;
                                                                }
                                                        }
                                                }
@@ -1478,8 +1478,11 @@ class DataHandler {
                if (isset($tcaFieldConf['dbType']) && \TYPO3\CMS\Core\Utility\GeneralUtility::inList('date,datetime', $tcaFieldConf['dbType'])) {
                        // Convert the date/time into a timestamp for the sake of the checks
                        $emptyValue = $dateTimeFormats[$tcaFieldConf['dbType']]['empty'];
-                       $timeOffset = $tcaFieldConf['dbType'] === 'date' ? 3600 * $GLOBALS['TYPO3_CONF_VARS']['SYS']['serverTimeZone'] : 0;
-                       $value = $value === $emptyValue ? 0 : strtotime($value) + $timeOffset;
+                       $format = $dateTimeFormats[$tcaFieldConf['dbType']]['format'];
+                       // At this point in the processing, the timestamps are still based on UTC
+                       $timeZone = new \DateTimeZone('UTC');
+                       $dateTime = \DateTime::createFromFormat('!' . $format, $value, $timeZone);
+                       $value = $value === $emptyValue ? 0 : $dateTime->getTimestamp();
                }
                // Secures the string-length to be less than max.
                if (intval($tcaFieldConf['max']) > 0) {