Closed nunoc66 closed 16 hours ago
Thanks for reporting!
However, it looks like this is a duplicate of #4270, so closing in favour of that one.
@duncanmcclean, are we sure this is a duplicate? Let me just explain my situation so we're certain.
The Statamic CP uses the user's local timezone. So when I create an entry, it has a datetime in my current timezone. However, the API saves that same time and puts the timezone of UTC.
Our site (and others I'm sure), are used by admins in multiple regions, meaning that my current time is different from someone else's and the API can't just use a different timezone. The API should continue to use UTC, and the Statamic CP should seemingly take the user's local time and convert it to UTC before saving it in the database.
Do you think solving the other ticket will solve the issue i'm describing above? I'd like the CP to remain in my local time and the API to remain in UTC, but it needs to convert my time to UTC when saving.
I'll re-open this - I just saw the words API / UTC & Timezones, which made me think it was the same thing. 😅
So when I create an entry, it has a datetime in my current timezone.
It's not really. When you pick June 5th at 8pm, what's to say it's your timezone? It gets saved as June 5th at 8pm in the configured timezone.
Saying that, we do have an issue open for general date/timezone improvements which would cover this.
It's definitely using the user's current time (see gif below). When I create an entry, it's super confusing because it's creating it using my current time, but when I publish it, the API is going to use UTC, so I have to manually change the time to UTC.
1) Is this how it behaves for everyone? They need to manually change the time every time they publish something?
2) Ideally, the CP would display my local time, but convert and save it as UTC.
If that's difficult, then when an entry is created, it'd be nice if it displayed UTC time and not my local time. Same thing for the 'Now' button, it should default to the current time in UTC, not my current time.
Yes clicking the now button will use whatever the time is on your computer, true.
All I'm saying is that it's basically just submitting a date string. There's no timezone information going up. If you send up 2024-10-31 1:00pm it's going to use that date string and the timezone configured in app.php
.
It's not ideal at all. We're aware of it. We should be using UTC everywhere and formatting it client side in the appropriate timezone. See https://github.com/statamic/ideas/issues/842 - it'll have to be fixed in a major version.
For now you should make your users aware that date fields are going to be expecting the timezone to be whatever is set in app.php
, which by default is UTC.
Bug description
When you're publishing an entry and set the publish date/time to Now, the UI shows the time in the user's timezone, for example Pacific time, however, in the Statamic API, it shows the same time, but in the UTC timezone.
How to reproduce
If you set the time to Now in an entry, or simply create a new entry which defaults to the publish time being the current time, it'll show your current time in your timezone, for example, 1:50 pm. However, when this entry is published, the Statamic API will show the same time (13:50), but it'll say the timezone is UTC, ruining the correct time of the entry.
Logs
No response
Environment
Installation
Fresh statamic/statamic site via CLI
Additional details
No response