statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
4.03k stars 530 forks source link

Statamic API shows incorrect time when using the 'Now' button #11030

Closed nunoc66 closed 16 hours ago

nunoc66 commented 1 day ago

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

Cache
Config: CACHED
Events: CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: postmark
Queue: sync
Session: database

Statamic
Addons: 1
Sites: 2 (...)
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.35.0 PRO

Statamic Addons
statamic/eloquent-driver: 4.15.2

Statamic Eloquent Driver
Asset Containers: file
Assets: file
Blueprints: eloquent
Collection Trees: file
Collections: eloquent
Entries: eloquent
Forms: eloquent
Global Sets: eloquent
Global Variables: file
Navigation Trees: file
Navigations: eloquent
Revisions: eloquent
Sites: file
Taxonomies: eloquent
Terms: eloquent
Tokens: file

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

duncanmcclean commented 1 day ago

Thanks for reporting!

However, it looks like this is a duplicate of #4270, so closing in favour of that one.

nunoc66 commented 17 hours ago

@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.

duncanmcclean commented 16 hours ago

I'll re-open this - I just saw the words API / UTC & Timezones, which made me think it was the same thing. 😅

jasonvarga commented 16 hours ago

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.

https://github.com/statamic/ideas/issues/842

nunoc66 commented 16 hours ago

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.

animation-8

jasonvarga commented 16 hours ago

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.