Like what we’re doing? Star us on GitHub!

Date Field: Timezone differs between admin panel input, and rest response

quornik
11 months ago
1 5

Bug Report

Date provided in Date Field is inconsistant with it's response form provided via Rest API. Propable cause is the timezone difference.

Expected Behavior

I provide data via Data Field. The provided date is like 24.05.2022, 10:00 AM. The rest response should be exactly the same.

Current Behavior

The date in response is however : 24.05.2022, 8:00 AM - two hours prior to what I've provided.

Possible Solution

Check the timezone of Admin frontend and adjust the timezone stamp accordingly, or build functionality to adjust timezone of API response via admin. If I understand correctly, at this point the response date is set via server time, which may differ from the timezone of the browser in whicz admin is working.

Steps to Reproduce

  1. Create Date Field in collection.
  2. Provide date to the field via admin panel.
  3. Chech the rest response of the field. In my case, the response is different.

Detailed Description

Current Payload version, Latest Chrome browser, UTC+1 timezone. Payload hostedn on Heroku, without the ability to granular control of the timezone of server.

  • DanRibbens
    Payload Team
    8 months ago

    Since we deterimined there isn't anything in Payload to fix I'm moving this to a discussion for others to see.

  • DanRibbens
    Payload Team
    11 months ago

    Thanks for reporting this @quornik. We're considering what the configuration settings will be for timezone and what effects it will have for the admin UI and APIs to solve the issue. We'll update again when we have a plan or fix ready.

  • quornik
    11 months ago

    Thanks @DanRibbens.
    You should also consider if I haven't rushed to quickly to call it a bug. Maybe it works properly and what it actually needs is just slightly updated documentation to the field. A warning of some kind that one should always localize the response.

    If you think about it, the best practice is to adjust the timezone always on frontend, after the dateObject has been received and befere it is displayed, because the user's context should determine the way date is interpreted & displayed.

    The scenario in which I had a problem with the way it works now, was this particular situation that I did not localize the response date before displaying. In every other situation it works fine.

  • jmikrut
    Payload Team
    11 months ago

    If you think about it, the best practice is to adjust the timezone always on frontend, after the dateObject has been received and befere it is displayed, because the user's context should determine the way date is interpreted & displayed.

    Exactly, @quornik. This isn't really a bug per se, rather, it's a potentially useful admin UX enhancement.

    We're thinking through how to make this happen as Dan said and will report back here once we have more!

  • lucaslcode
    2 months ago

    Here's a use case that doesn't fit the current setup too well - I'm adding events using payload, however the events I'm adding take place in a different timezone to where I am currently.

    It seems payload converts my local time to UTC and stores that - it means I have to do some calculating to input the time I want as it would be in my current timezone.

    I think a possible solution would be to have the ability to select the timezone of the time you are entering, though I'm not sure if react-datepicker supports this.

Open the post
Continue the discussion in GitHub
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More