Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Time and date picker adjusts time based on timezone #2558

Closed
galingong opened this issue Mar 24, 2024 · 3 comments
Closed

Time and date picker adjusts time based on timezone #2558

galingong opened this issue Mar 24, 2024 · 3 comments

Comments

@galingong
Copy link
Contributor

galingong commented Mar 24, 2024

Description

time_picker field would adjust the value displayed in the field based on OS/browser timezone ie. will not display the value stored in the DB, but treats that value as if it was UTC and the displayed value was local. Value in store is correct so it should be something related to frontend/flatpickr.js.

Edit: date_picker with time is also affected.

Steps to reproduce

Set your OS timezone to something other than UTC and compare DB stored value and the field.

Expected result

No timezone adjustment

Actual result

Value in field offset by timezone

Versions

Twill version: 2.3.0
Laravel version: 10

@galingong
Copy link
Contributor Author

galingong commented Mar 24, 2024

It's probably because in DatePicker.vue on line 152 date-fns.parse is called with date + 'Z' and format + 'X' so the parsed value would be offset. Removing the Z (and since it's not needed anymore, also the X from format) seems to resolve the issue.

Edit: Had to also edit flatpickr format on line 135 to dateFormat: self.enableTime ? 'Y-m-d H:i' : 'Y-m-d' to completely resolve the problem.

@galingong galingong changed the title Time picker adjusts time based on timezone Time and date picker adjusts time based on timezone Mar 24, 2024
@ifox
Copy link
Member

ifox commented May 30, 2024

The offset is intended to improve the user experience. Dates should always be stored in UTC in the database, but you don't want your users to have to do mental gymnastics with timezones when using date and time pickers in the CMS.

Are you reporting a bug with this implementation, or is it more that you were looking to disable that behavior?

@galingong
Copy link
Contributor Author

To be honest, at the point when I opened this issue I was completely oblivious to the fact that it was good practice to store UTC dates in the DB - answering your question - it's not a bug if you followed best practices, so we might as well close this. But still it would be nice to be able to store and display datetime values independently from timezones. Do you have an idea if it would be possible currently?

@area17 area17 locked and limited conversation to collaborators May 31, 2024
@ifox ifox converted this issue into discussion #2592 May 31, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants