Bug #80349
openEpic #77562: Misbehaviors with datetime values and timezones
Extbase mapping of \DateTime for integer values does not set timezone with region string but only offset
0%
Description
Currently the extbase DataMapper handles the conversion of integer values to \DateTime
in https://git.typo3.org/Packages/TYPO3.CMS.git/blob/HEAD:/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php#l315
like this:
return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($targetType, date('c', $value));
Therefore the value itself will be correct but the timezone will be e.g. "+01:00" or similar instead of e.g. "Europe/Vienna".
That means it will be fine as long as one doesn't modify the date.
For instance, a date like March 20th 00:00:00 with \DateTimeZone "+01:00" when calling $date->modify('+1 month')
if one were to use "Europe/Vienna" the date would switch to daylight savings time.
How the result with the \DateTimeZone "+01:00" then the result will be April 20th 00:00:00 with \DateTimeZone "+01:00" which means the \DateTimeZone is wrong as with daylight savings time it would actually be "+02:00".
This means a comparison of a date in the correct timezone to the calculated one might fail or be of by the difference between daylight saving time and normal time.
However, if the \DateTimeZone is the regional \DateTimeZone like e.g. "Europe/Vienna" this will work correctly.
The easiest solution is probably to add $date->setTimezone prior to return the \DateTime.