Date producers should apply the current timezone consistently

Created on 11 July 2024, 3 months ago
Updated 19 August 2024, about 1 month ago

Problem/Motivation

In most situations the dates returned by our data producers use the correct timezone as determined by the TimeZoneResolver. However there are some cases where Drupal uses UTC time internally:

  • Data stored in date fields (and other storage that relies on the DateTimeIso8601 data type) is always returned in UTC since this is hardcoded in DateTimeIso8601::getDateTime().
  • Computed date fields use UTC time, since they instantiate the date using DateTimeItemInterface::STORAGE_TIMEZONE. Ref. DateTimeComputed::getValue().

This happens for example when using date range fields. The start_date and end_date properties are returned in UTC time by the data producer.

Known workaround

It is possible to work around this by appending the timezone information to the date format in the GraphQL query (e.g. date(format: "Y-m-dTh:i:s Z") to append the used timezone offset in seconds) and recalculating the correct time in JS.

Proposed resolution

Similar to how Drupal handles its date output, we should always apply the default timezone so all times are consistent. Drupal core also allows to override the default timezone in the theme which is something we can consider as a future feature request.

In the Drupal theming system the corresponding code that handles this is DateTimeFormatterBase::setTimeZone().

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇧🇬Bulgaria pfrenssen Sofia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024