Bug #91838
closedTCA l10n_mode="exclude" with TCA config dbType='datetime' set wrong timezone in translated records
0%
Description
For TCA fields of the type "datetime" where "l10n_mode=exclude" is set, the DB field (which is already in UTC format) is converted to UTC again when the translated data records are synchronized with the original data record. The reason is that the time zone information is missing in the database.
Example:¶
TCA Configuration:
'date' => [
'exclude' => true,
'label' => 'date',
'config' => [
'type' => 'input',
'renderType' => 'inputDateTime',
'dbType' => 'datetime',
'eval' => 'datetime,required'
],
'l10n_mode' => 'exclude',
],
Mysql Field
date datetime,
LocalConfiguration:
'SYS' => [
'phpTimeZone' => 'Europe/Berlin',
'serverTimeZone' => 'Europe/Berlin',
],
If I save the field with the value " 14:00 03-09-2020" then this date is sent in the format "2020-09-03T*14:00*:00Z" (I think the time zone is already set correctly in the frontend) and stored in the database with the date "2020-09-03 14:00 :00". The correct date will also be saved correctly in the translated data set.
But when I edit and save the translated dataset, the date of the original dataset "2020-09-03 14:00:00" is copied from the database (without time zone). The datahandler converts the date into UTC format and the new "wrong" date "2020-09-03 12:00:00" is written back to the database.
I think it's the same problem as issue #81228
The following patch has worked for me
--- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php
+++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
@@ -1966,7 +1966,7 @@ protected function checkValueForInput($value, $tcaFieldConf, $table, $id, $realP
// Convert the date/time into a timestamp for the sake of the checks
$emptyValue = $dateTimeFormats[$tcaFieldConf['dbType']]['empty'];
// We store UTC timestamps in the database, which is what getTimestamp() returns.
- $dateTime = new \DateTime($value);
+ $dateTime = new \DateTime($value, new \DateTimeZone('UTC'));
$value = $value === $emptyValue ? null : $dateTime->getTimestamp();
}
}