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 15 commits into
base: master
Choose a base branch
from
Draft

[6.x] Store dates as UTC #11409

wants to merge 15 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.

A more detailed PR description is to follow.

Storage

We aren't changing the format dates are saved in, just the timezone. This means dates and times will continue to be saved like this:

articles/2025-01-27.hello-world.md
title: Flat Camp 2024
start_date: 2024-06-11
end_date: 2024-06-14
registration_closes: 2024-06-01 12:42:42

However, instead of 10:00 being saved (for an app in New York), it'd save as 15:00, the UTC time. This might end up being a little confusing, but we'll try to make it clear in the documentation.

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. We'll then display them 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