Bug #80349

Epic #77562: Misbehaviors with datetime values and timezones

Extbase mapping of \DateTime for integer values does not set timezone with region string but only offset

Added by Andreas Allacher over 2 years ago. Updated 2 months ago.

Status:
New
Priority:
Must have
Assignee:
-
Category:
Extbase
Start date:
2017-03-20
Due date:
% Done:

0%

TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

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.


Related issues

Related to TYPO3 Core - Feature #80559: datetime and time handling should always have timezone information Closed 2017-03-29
Related to TYPO3 Core - Bug #68651: Datetime() properties have wrong timezone Accepted 2015-07-30

History

#1 Updated by Mona Muzaffar about 2 years ago

  • Related to Epic #80852: Datetime handling in backend added

#2 Updated by Benni Mack about 2 years ago

  • Target version changed from 8 LTS to next-patchlevel

#3 Updated by Gerrit Code Review about 2 years ago

  • Status changed from New to Under Review

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/52952

#4 Updated by Paul Golmann about 2 years ago

I found myself with the same problem. I've created a patch (see below for explanation).

The problem is, as far as I can see:

date('c', $value)
creates a string representing the date/datetime including the timezone, which is what we want. But the string representation (ISO 8601) encodes the timezone as a offset (e.g. 2017-10-20T00:00:00+02:00 if the local server time (SYS['phpTimeZone']) is set to Berlin/Europe). That leads the resulting \DateTime to only have the offset but not the timezone region. That means when "working" on the DateTime information about e.g. the summer time/daytime saving gets lost. For me that caused shifting of dates around the (german) summer time change in October this year using a calendarize configuration with a frequency.

In the patch I've aligned the code for mapping timestamps with that of datetime database fields. That means that the timezone will correctly be set as Europe/Berlin instead of +02:00.

Greetings. Paul

#5 Updated by Gerrit Code Review about 2 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/52952

#6 Updated by Paul Golmann about 2 years ago

  • Related to Bug #68651: Datetime() properties have wrong timezone added

#7 Updated by Paul Golmann about 2 years ago

  • Related to Bug #68651: Datetime() properties have wrong timezone added

#8 Updated by Paul Golmann about 2 years ago

  • Related to deleted (Bug #68651: Datetime() properties have wrong timezone)

#9 Updated by Gerrit Code Review about 2 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/52952

#10 Updated by Markus Klein about 2 years ago

  • Parent task set to #77562

#11 Updated by Riccardo De Contardi about 2 years ago

  • Related to deleted (Epic #80852: Datetime handling in backend)

#12 Updated by Gerrit Code Review over 1 year ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/52952

#13 Updated by Benni Mack 8 months ago

  • Status changed from Under Review to New

#14 Updated by Benni Mack 2 months ago

  • Target version changed from next-patchlevel to Candidate for patchlevel

Also available in: Atom PDF