Project

General

Profile

Actions

Bug #96049

open

No timezone in Context API date aspect

Added by Tim Lochmüller over 2 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2021-11-22
Due date:
% Done:

0%

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

Description

Hey everyone,

we use a TS condition to check the date for a special requirement:


[date("YmdHi") > 202111220800 && date("YmdHi") < 202111292359]
  # Do special stuff
[end]

We found out, that the date method do not respect the configured timezone of the TYPO3 instance. The reason is, that the TYPO3\CMS\Frontend\Http\Application (and also the fallback in the Context class itself) create the \DateTimeImmutable for the date aspect with this code:

new \DateTimeImmutable('@' . $GLOBALS['EXEC_TIME'])

But creating a DateTime from Timestamp, will result in a DateTime without timezone: https://www.php.net/manual/en/datetime.construct.php ("The $timezone parameter and the current timezone are ignored when the $datetime parameter either is a UNIX timestamp (e.g. @946684800)"). So the "DateTimeAspect" property for getting the timezone is always null/UTC and the date is always wrong (+1h in my case for Europa/Berlin), if the TYPO3 installation is not using UTC timezone.

I test the code with this implementation...

$dateTime = new \DateTime('@' . $GLOBALS['EXEC_TIME']);
$dateTime->setTimezone(new \DateTimeZone(date_default_timezone_get()));
$dateTimeImmuntable = \DateTimeImmutable::createFromMutable($dateTime);

... and the TypoScript condition works well, and also the "DateTimeAspect" timezone property is filled in the right way.

Either this is the described bug or we should add a notice to functions that are based on Context API that the timezone is always UTC and drop the timezone property (which is currently always UTC): https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Conditions/Index.html#date & https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Context/Index.html#datetime-aspect

Does anyone have any feedback on this?

Regards,
Tim

No data to display

Actions

Also available in: Atom PDF