Skip to content
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

Use ISO Date format in flatpickr #2462

Merged

Conversation

phantomwhale
Copy link
Contributor

What is this pull request for?

Currently the date/time being displayed in flatpickr is (correctly) set to the user's current timezone (as detailed in
flatpickr/flatpickr#1532)

Where this breaks is when it's sent back to the server to update the page. Flatpickr sends back the date in it's default format, which does not include any timezone information. Rails then takes that timestamp and assumes it's in UTC when saving it to the database.

Which means a user in UTC+10 can save a page to go public at 1PM local time, and after saving, it will actually be set to 11PM local time (== 1PM UTC)

By forcing the underlying string value in the form to adopt the ISO standard, Rails can parse both the time AND timezone from the incoming data, and ensure the timestamp is saved to the correct UTC time in the database, fixing the bug

Closes #2461

Screenshots

In both cases, opening up a page properties modal, marking it to go public at 1PM local time (UTC+10)

Screenshot 2023-04-21 at 12 09 03 pm

The expected result of this would be the timestamp persisted as public_on = 3AM UTC time in the database. Without the patch, this gets incorrectly persisted as public_on = 1PM UTC time.

Screenshots below show chrome dev tools XHR payload, the server side logs for the incoming PATCH request, and the server side logs for the underlying ActiveRecord DB update, to showcase the differences in the data flow

Before the patch:

Screenshot 2023-04-21 at 12 50 43 pm

Screenshot 2023-04-21 at 12 51 10 pm

Screenshot 2023-04-21 at 12 52 08 pm

After the patch:

Screenshot 2023-04-21 at 12 10 05 pm

Screenshot 2023-04-21 at 12 14 34 pm

Screenshot 2023-04-21 at 12 16 37 pm

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

Currently the date/time being displayed in flatpickr is (correctly) set
to the user's current timezone (as detailed in
flatpickr/flatpickr#1532)

Where this breaks is when it's sent back to the server to update the
page. Flatpickr sends back the date in it's default format, which does
not include any timezone information. Rails then takes that timestamp
and assumes it's in UTC when saving it to the database.

Which means a user in UTC+10 can save a page to go public at 1PM local
time, and after saving, it will actually be set to 11PM local time
(== 1PM UTC)

By forcing the underlying string value in the form to adopt the ISO
standard, Rails can parse both the time AND timezone from the incoming
data, and ensure the timestamp is saved to the correct UTC time in the
database, fixing the bug
@phantomwhale
Copy link
Contributor Author

I've looked over the existing specs; is this functionality that's easily added into the specs without adding a lot more complexity to the suite?

@tvdeyen
Copy link
Member

tvdeyen commented Apr 21, 2023

Nice fix 😃

I think a spec is only possible if we would write a e2e feature spec. There is the "link dialog" feature spec that could lead as example. But if this is not easy to implement, we can also just add a Jest unit spec that verifies the option is set.

@tvdeyen tvdeyen self-requested a review April 26, 2023 08:10
@tvdeyen
Copy link
Member

tvdeyen commented Apr 26, 2023

@phantomwhale do you mind looking into a leats a Jest unit test? I would like this to be formalized in a spec, so this cannot happen again

@tvdeyen tvdeyen merged commit 945b753 into AlchemyCMS:main May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Date picker does not appear to save time in correct timezone?
2 participants