Project

General

Profile

Actions

Bug #68651

open

Epic #77562: Misbehaviors with datetime values and timezones

Datetime() properties have wrong timezone

Added by Martin Bless over 8 years ago. Updated over 2 years ago.

Status:
Accepted
Priority:
Must have
Assignee:
Category:
Extbase
Start date:
2015-07-30
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Summary:

The TYPO3 backend does it right. Would be great to have Extbase doing right as well!

Details:

My timezone is set to "Europe/Berlin" ('phpTimeZone' => 'Europe/Berlin')

In the backend everything is ok: I can enter "31-10-2015 00:00" in a field 'firstDay' and it's always correct. But in the frontend, with Extbase/Fluid and

<f:format.date format="d.m.Y">{offer.firstDay}</f:format.date>`

I will see "30.10.2015" as output, because that date has been calculated for timezone GMT/UTC, which is "30-10-2015 22:00" which is 2 hours less than our current CEST (central european summer time).

The problem is, that Extbase instantiates the offer.firstDay DateTime() object with timezone_type => 1:

object(DateTime)[1]
  public 'date' => string '2015-10-30 22:00:00' (length=19)
  public 'timezone_type' => int 1
  public 'timezone' => string '+00:00' (length=6)

while it actually needs the correct timezone information.

I can correct that in the following manner:

// we use $now to copy the timezone from
$now = new \DateTime();
firstDay->setTimeZone($now->getTimezone());

After that procedure var_dump($firstDay) says:

object(DateTime)[1]
  public 'date' => string '2015-10-31 00:00:00' (length=19)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Berlin' (length=13)

And now $firstDay will give the same result that the backend gives for

<f:format.date format="d.m.Y">{offer.firstDay}</f:format.date>`

The result is now the expected "31.10.2015".

Earlier discussions

When searching for a solution I found an earlier discussion of that issue here: http://lists.typo3.org/pipermail/typo3-project-typo3v4mvc/2010-July/006013.html


Files

DateViewHelper.php (6.26 KB) DateViewHelper.php modified TYPO3 7.6 viewhelper Jörg Velletti, 2016-12-09 14:41
330.png (144 KB) 330.png Martin Bless, 2017-12-15 14:37

Related issues 7 (2 open5 closed)

Related to TYPO3 Core - Bug #72878: wrong datetime handling, they are not UTC in dbClosed2016-01-21

Actions
Related to TYPO3 Core - Bug #80008: Avoid warning dialog when closing records with start-, endtime valuesClosedFrank Nägler2017-02-24

Actions
Related to TYPO3 Core - Feature #80559: datetime and time handling should always have timezone informationClosed2017-03-29

Actions
Related to TYPO3 Core - Bug #80679: Input field eval datetime in FlexForm converts to wrong timestampClosed2017-04-04

Actions
Related to TYPO3 Core - Bug #80349: Extbase mapping of \DateTime for integer values does not set timezone with region string but only offsetNew2017-03-20

Actions
Related to TYPO3 Core - Bug #68849: Unstable persistence handling of DateTime (don't get what you set)Closed2015-08-07

Actions
Related to TYPO3 Core - Bug #79613: Saving wrong Date into DB if Field is of type DATENew2017-02-03

Actions
Actions

Also available in: Atom PDF