Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Store dates as UTC #11409

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft

[6.x] Store dates as UTC #11409

wants to merge 27 commits into from

Conversation

duncanmcclean
Copy link
Member

@duncanmcclean duncanmcclean commented Jan 30, 2025

This pull request ensures that dates in Statamic are always stored as UTC, then transformed to the relevant timezone when they're displayed.

Storage

For the most part, we aren't changing the format dates are saved in, just the timezone.

The only caveat to that is that we'll always save dates with time, even when the time_enabled option is disabled. This change ensures that "midnight" for the selected day is midnight in the local timezone, rather than midnight in UTC.

One potential downside to always saving dates/times in UTC is that instead of 10:00 being saved (for an app in New York), it'd save as 15:00, which might end up being a little confusing. We'll make this clear in the documentation / update guide.

Update Process

During the update process, an update script will run to convert all dates to UTC.

It'll attempt to find all date fields (including those in Grids, Bards, Replicators, etc) and update them as needed.

The update script will look through entries/terms/globals/users. If you need to convert dates elsewhere (like in a custom addon), you'll need to create your own update script.

Once the update script is complete, you can change your application's timezone back to UTC, as strongly recommended by the Laravel documentation.

/*
 |--------------------------------------------------------------------------
 | Application Timezone
 |--------------------------------------------------------------------------
 |
 | Here you may specify the default timezone for your application, which
 | will be used by the PHP date and date-time functions. The timezone
 | is set to "UTC" by default as it is suitable for most use cases.
 |
 */

'timezone' => env('APP_TIMEZONE', 'UTC'),

Control Panel

In the Control Panel, dates are always returned & sent to the server in UTC. They'll be displayed using the user's local timezone.

Frontend

We've added a new display_timezone configuration option which'll determine the timezone used when displaying dates on the frontend.

REST API & GraphQL API

Dates in the REST API & GraphQL API will always be returned as UTC. This allows developers to transform them as needed on their end.


Related: #11388.
Closes statamic/ideas#842.

@duncanmcclean duncanmcclean changed the title Store dates as UTC [6.x] Store dates as UTC Jan 30, 2025
@sylvesterdamgaard
Copy link
Contributor

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants