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

malavya’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.

Cottser’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?

Cottser’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.