Bug #68849
closedUnstable persistence handling of DateTime (don't get what you set)
0%
Description
DATE or DATETIME database values are treated as UTC during the mapping of an object and the php default time zone (date_default_timezone_get()) is applied to it. E.g.: If your php default time zone is "Europe/Berlin" (timezone_type: 3), it is summer and you have stored 2015-08-07 13:00:00 in the Databse you will get a DateTime object with the date 2015-08-07 15:00:00.
This is only done if your dates are stored in a column of type DATE or DATETIME. If you store the dates in a column of type INTEGER as unix timestamp the date values are not converted. Therefore, changing the olumn type of the database changes the values you get from a repository. This, however, cannot be correct.
Because the TCE in the Backend does not convert any dates/time zones, you will see different times in FE and BE.
But all of that is not the biggest problem. What is really annoying is the fact that the DateTime objects are not converted back to UTC during saving to DB (persistAll ()). As a result, every time you read and write a DateTime object your Time is increased/ decreased by the time offset of your default php time zone (in my case 2 hours).
Example¶
DB value for start: 2015-08-07 13:00:00
DB value after execution the following piece of code: 2015-08-07 15:01:00
public function dateTestAction() { $obj = $this->operatingTimeRepository->findByUid(1); $obj->getStart()->add(new \DateInterval('P0Y0DT0H1M')); // add one minute $this->operatingTimeRepository->update($obj); }
Involved code:¶
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php
save to db: getPlainValue()
read from db: mapDateTime()
possible solution:¶
Remove the conversion during read from Database and let the extension programmer decide how to deal with time zones.
See attached patch.
related:¶
Files