Problem/motivation

When using 'User's timezone' handling:
The 'timezone' value of a date field does not immediately update when a user changes their timezone. The value is cached so the date appears in the cached 'timezone' for all users until the caches are cleared?

(Even when date object caching is not enabled in the field settings).

Steps to recreate

On a fresh install, with the Devel module to help inspect the node data:

Create a new content type with a Date field, with the timezone handling set to "User's time zone".
Set your timezone to Europe/London.
Create an event on a certain date at 9am.
View the event node, and the time is displayed as 9am.
With Devel enabled, we can see the 'timezone' part of the node's date field data is Europe/London.

Now change your timezone to Pacific/Galapagos.
View the node, it still displays as 9am.
With Devel enabled we can see the 'timezone' is still Europe/London.
With Devel if you dsm(date_default_timezone()); the timezone is Pacific/Galapagos.

Now clear the caches (Config > Development > Performance)
The event node displays the time correctly in your timezone.

Solution?

Why is the 'timezone' being stored as part of the field? Surely it should never be used and we should just access date_default_timezone() directly when we need it?

Comments

JKingsnorth’s picture

Title: Timezone value changing with "User's time zone" handling » User's timezone should not be cached in field
Issue summary: View changes

This is a misunderstanding of how the date module works. The 'timezone' is the timezone that the date should be displayed in. However it seems to be getting cached, so isn't immediately updated when a user changes their timezone.

I'm updating the issue accordingly.

JKingsnorth’s picture

Issue summary: View changes
DamienMcKenna’s picture

This can also be seen when a field is set to not use timezones - the first visitor to view the page has their timezone cached, all future views of that entity then have the original request's timezone used.

I'm considering removing the date caching entirely, see #3241762: Remove date value caching for details.