-
-
Notifications
You must be signed in to change notification settings - Fork 553
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
Configured timezone is not respected in the API #4270
Comments
Like you've said, it looks like this only applies to the API. |
mb its not a bug, laravel use iso-8601 in resources, so, your date is converted to UTC in API. You need to convert date from API to your timezone |
You should never store your dates in another timezone than UTC, Carbon documentation links to this great article to explain why https://kylekatarnls.medium.com/always-use-utc-dates-and-times-8a8200ca3164. |
I'm not displaying the dates to the user. It's essentially a comparison in my code that something should happen only if the date condition is met. When using UTC and users from Europe/Berlin are using the site, the rendered data is not correct. Right now, UTC is 15:45, while EU/Berlin is 17:45. |
If you want date formats in JSON to be your timezone and not UTC (which is Carbon's default), you could make an API middleware and add:
the |
Bug Description
When creating a date field in a fieldset, it uses UTC by default and not the timezone set in
config/app.php
. In my case it is'timezone' => 'Europe/Berlin'
. When setting the date, for example2021-09-16
, the output is"2021-09-15T22:00:00.000000Z"
.This makes it more complicated to compare dates with
now()
. So the bug, at least it seems to me, is that Statamic does not respect the timezone set in my app. Basically, I have to do this in order to make it work:This seems to be related to the Content API only.
Environment
Statamic 3.2.4 Pro
Laravel 8.61.0
PHP 8.0.10
jacksleight/bard-paragraph-style 1.0.0
jonassiewertsen/statamic-livewire 2.7.0
octoper/statamic-blade-components 1.0.1
optimoapps/statamic-bard-text-align 1.0.2
Install method:
The text was updated successfully, but these errors were encountered: