[TYPO3-mvc] [6.x.+] DataMapper assumes that DateTime is stored in UTC, but it's not true

Marcus Biesioroff marcus at typo3.pl
Mon Mar 23 15:38:05 CET 2015


In Extbase 6.x+ DataMapper::mapDateTime() assumes that native DateTime dates are stored in DB with UTC TimeZone so it forces the TZ conversion to the current one, link: 

github.com/TYPO3/TYPO3.CMS/blob/TYPO3_6-2/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php#L260

Of course it's wrong assumption as:

* TCE forms doesn't respect it. Setting in date field '2015-03-23 12:00:00' will save it as is, although my TimeZone is GMT+1 (so it should be stored as '2015-03-23 11:00:00'
* Model's setters also doesn't respect it, the same as above it will be saved to DB as '2015-03-23 12:00:00'
* Extbase returns wrong date ant time (shifted a few hours according to difference of the current TZ vs UTC) '2015-03-23 13:00:00' for given date
* if there's setting in the Install tool $GLOBALS['TYPO3_CONV_VARS']['SYS']['phpTimeZone'] - which is resolved in the Bootstrap class, why can't we use it to mapping the Date/DateTime fields? In such case if some wants to use UTC - can use UTC, but in many cases it will be just another TimeZone - i.e. CET/GMT+1 in my case?
* This way it's not possible handle easy dates for different TimeZones i.e. by adding custom TimeZone field to the model

Dirty and fast and most important - working - workaround is avoiding the UTC forcing in the linked mapDateTime() method, but I wonder if this shouldn't be fixed in the core like:

..  elseif ($storageFormat === 'date' || $storageFormat === 'datetime') {
			// native date/datetime values are stored in ... current TimeZone (UTC storing is NOT handled properly in all aspects!)
			$currentTimeZone = new \DateTimeZone(date_default_timezone_get()); // default TZ already set in the Bootstrap!
			$mappedDateTime = new \DateTime($value, $currentTimeZone);
			return $mappedDateTime;
		} else ...

Has this some side effects in 6.2 ? I don't like the idea that I would need to convert dates to UTC each time for saving and getting in non-extbase occurrences especially if all server works in only ONE timezone (that means TCE hooking and overriding the setters).

IMHO DateTime field should be considered the same way as any T3 record in default language - it's not English or Danish or anything else... it's default due to the installation context.  

P.S. Sorry for lack of formatting, I've no idea how to format code block on the forum :/


More information about the TYPO3-project-typo3v4mvc mailing list