Issue Bug Closed

#68651Datetime() properties have wrong timezone

Martin Bless 07/30/15, 21:02 updated 08/12/25, 14:35

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

Reviews 2