-
-
Notifications
You must be signed in to change notification settings - Fork 554
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
duncanmcclean
wants to merge
79
commits into
master
Choose a base branch
from
utc-dates
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[6.x] Store dates as UTC #11409
+1,445
−243
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In that case, we have nothing to do here.
🎉 |
The update script also handles some formatting changes (like adding the time to "just date" fields).
Dates are always UTC.
# Conflicts: # src/Providers/ExtensionServiceProvider.php
All Date fields have time now. They just don't all display it.
Otherwise, we won't be able to convert it from UTC to the site's display timezone.
…n the app timezone.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request ensures that dates in Statamic are always stored as UTC, then converted to the relevant timezone when they're being displayed.
Storage
For the most part, we aren't changing the format dates are saved in, just the timezone. Previously, dates and times were stored in whatever timezone you entered them in, but now they're always stored in UTC:
^ In this example: Italy is 1 hour ahead of UTC. 🇮🇹
One thing worth noting is that time will now always be saved alonside dates, even when the
time_enabled
option is disabled. This helps to ensure that "midnight" is relative to whatever timezone your users are in.Control Panel
The Date fieldtype now converts the UTC date/time value to your operating system's timezone, and vice versa. It'll always send the UTC value back to the server.
Frontend
When the Date fieldtype is augmented, it will return a UTC Carbon instance. Only when you output a date in your template will it be converted to the
display_timezone
configured inconfig/statamic/system.php
.Note
The timezone conversion will only take place when the request passes through Statamic's
Localize
middleware.You should ensure you're applying the
Localize
middleware (or preferably the entirestatamic.web
middleware group) to any custom routes in your application.Modifiers
When using modifiers on Date fields (or any other Carbon instances), it's important to know that they'll be working with the UTC values, rather than "localized" value.
There are two ways you can workaround this:
You can add the
timezone
modifier (ortz
for short) to the start of your modifier "chain". It'll convert the Carbon instance to the "display timezone" you have configured:Alternatively, you can enable the
localize_dates_in_modifiers
option in yourconfig/statamic/system.php
config file, which'll automatically convert dates to your display timezone before reaching any modifiers:To ease the v6 upgrade process, this setting has been enabled by default for existing sites.
REST API & GraphQL API
Dates returned by the REST API & GraphQL API will always in UTC. This allows you to transform them, as needed, on your frontend (or wherever you're consuming the API).
Update Script
During the update process, an update script will be run to convert dates in your content to UTC.
The update script will also add two config options to your
config/statamic/system.php
config file:display_timezone
localize_dates_in_modifiers
You can read more about these config options under the "Frontend" heading above.
Once the update script has completed, we strongly recommend changing your app's timezone to UTC. You can configure the timezone in your
config/app.php
config file:Closes #4270.
Closes #5748.
Closes #8339.
Closes #10896.
Replaces #8636.
Replaces #10166
Replaces #11388.
Closes statamic/ideas#842.
Goes alongside statamic/eloquent-driver#398.