Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)
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 aspublic_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:
After the patch:
Checklist