-
-
Notifications
You must be signed in to change notification settings - Fork 571
[6.x] Improved Timezone Handling #11409
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
Merged
Merged
Conversation
This file contains hidden or 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.
🎉 |
Otherwise, tests which rely on the default user blueprint will fail.
…nally in upcoming commit.
…ailures in others when you rerun the suite
…d, if they arent the start of the day
jasonvarga
approved these changes
Mar 11, 2025
This was referenced Mar 11, 2025
This was referenced Mar 12, 2025
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 makes a number of improvements to how Statamic handles timezones.
To avoid updating content in existing sites unnecessarily, Statamic will continue to store dates using the application timezone, just like it does right now in v5.
Then, for new sites, we recommend keeping the app timezone as
UTC
and simply changing thedisplay_timezone
option inconfig/statamic/system.php
instead.Optional timezone migration
Initially we were going to force migration of content into UTC, but went back on that idea after we decided too much content would get touched. However the migrator tool worked pretty well so we'll leave it available for anyone who wants to change the app timezone. This command will update date fields throughout your content.
You should replace
America/New_York
with whatever timezone you want to convert dates from (eg. your old app timezone). We highly recommend taking a backup of your site before running the command, especially if you're storing content in a database.After the command has run, you can change your app timezone to
UTC
.Control Panel
The Date fieldtype will convert the date/timestamp to UTC, which'll then get localized to the user's timezone using JavaScript.
Obviously, the opposite happens when the user updates the date/time. It gets converted back from the user's timezone to UTC. Then, when the entry is saved, it'll be converted back to the application's timezone.
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 using a new
display_timezone
option inconfig/statamic/system.php
.'display_timezone' => null,
When
null
, it'll fall back to the app timezone.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).
Closes #4270.
Closes #5748.
Closes #8339.
Closes #10896.
Replaces #8636.
Replaces #10166
Replaces #11388.
Closes statamic/ideas#842.
Associated PRs