Problem/Motivation

When formatting datetime in twig and printing the timezone

{{ datetime|date('g:i A T') }}

An anonymous user has a null timezone and therefore twig timezone conversion gives unexpected results.

Proposed resolution

The default timezone for anonymous users should be the site's default timezone.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

arknoll created an issue. See original summary.

mikemiles86’s picture

imalabya’s picture

Can you give more information regarding the issue?

I tried recreating the issue by printing the timezone in twig file and the time is showing up correctly for anonymous user.

Can you check up what is the `php.ini` time settings for your system? By default it is empty and Drupal takes up UTC as the site timezone.

bdimaggio’s picture

I commented out the "date.timezone =" line in my php.ini, cleared caches, ensured that page cache was set to something (see #2638678: date.timezone not being set in php.ini results in exceptions) and still wasn't able to reproduce this.

star-szr’s picture

Issue tags: +Twig
killua99’s picture

I did create a field (Date) and try to print the value with twig.

{{ node.field_date_and_time[0].value|date('U')|format_date('custom', 'H:i T', 'Europe/Stockholm') }}

The result was "12:00 CET"

My date.timezone is UTC and Default Timezone is Europe/Stockholm on my php.ini

I'm running without any CacheBackend system.

Also this is happening to the latest 8.1.0-beta2

cilefen’s picture

Can someone on this issue consider whether this is a Major bug and update accordingly if it is not?

cilefen’s picture

Oh, the issue title refers to working with a user object, but is this a universal problem with dates?

star-szr’s picture

Component: user system » theme system
Priority: Major » Normal
Issue tags: +Needs steps to reproduce, +Needs issue summary update

Hopefully this is not hijacking this issue, but…

If I'm interpreting the bug report correctly this might be a universal problem with dates and Twig from my understanding, because our Twig environment doesn't know about Drupal's TZ handling as far as I know. I'm not sure how to solve that but updating the component for now. This doesn't seem major to me because there are definitely workarounds like using preprocess and/or the |format_date Twig filter in core.

One question I have is how do our cache systems (cache contexts etc.) work with different user timezones?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

sime’s picture

Status: Active » Closed (cannot reproduce)

Using the twig syntax from the issue summary ({{ datetime|date('g:i A T') }} ) I saw the correct date timezone using twig. It reflected:

  • the site's regional settings for anonymous user
  • and the user's timezone settings for logged in user

I am marking this unable to reproduce, please reopen if this seems incorrect.