-
Notifications
You must be signed in to change notification settings - Fork 87
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
fix: date-picker bug for negative UTC timezones attempt 3 #6261
Conversation
For |
Looking at the main problem, I would warrant that the client should not need to know about any server implementation. no past dates: prevent past dates according to client time All client should do is to set the date object to start of day selected before passing to the client, no need to convert to UTC. The |
So regarding this, should we stick to the implementation in this PR as of now and open a new issue for handling date 'normalisation' on backend? FYI:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems correct, lgtm. Can we have some unit tests on the date util functions to ensure that the two functions work as expected?
ah yes, we should have that in place before pushing! thanks @karrui will add it in 👍 🌮 |
Regarding unit tests for date utils, I'm finding it particularly hard to test |
Can try mocking with |
Thanks for the suggestion! It works |
- (FE) normalize dates to UTC before storing in DB - (FE) load normalized dates to local timezone - (BE) remove adjustments due to timezone
5eaa50a
to
51a8169
Compare
Rebased to develop and force pushed so that Playwright Tests can pass. New commits since last review are "fix: normalizeDateToUtc to return Date object" and after. |
const localDate = new Date(Date.parse(dateString)) | ||
const utcDate = new Date(Date.parse(`${dateString}+00:00`)) | ||
|
||
const result = DateUtils.normalizeDateToUtc(localDate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to assert before and after the util is called to ensure dates are different first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm I don't think this is especially valuable as an assertion as ideally the test should still pass when the local time is UTC. But I get it that there is no value in the test if the local time and UTC time is the same, I guess. Will it be better that this test is removed or that the local time here is set as SGT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rationale is to assert that the mock date library is also working, just in case :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha okay, I'll add the assertion for the positive/negative utc tests then! yea when i tried the library I did print the dates to make sure hahaha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checks added here: d232fad
Note: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm~
* fix: date-picker bug for negative UTC timezones attempt 3 (#6261) * fix: remove timezone from datepicker * fix: datepicker bugs due to timezones - (FE) normalize dates to UTC before storing in DB - (FE) load normalized dates to local timezone - (BE) remove adjustments due to timezone * docs: futureOnly and pastOnly validators * refactor: allow null inputs for new date util fns * fix: date normalization fns to use date as numbers * refactor: remove unnecessary var assignment * fix: unset date validation * fix: compare to dates in earliest & latest tzs * fix: date validation bug in release v6.41.0 * fix: restore original date validators * fix: normalizeDateToUtc to return Date object * test: frontend date utils * build(deps): add timezone-mock to mock local time * test: date utils in the most extreme timezones * test: add check to ensure that timezone-mock works * chore: bump version to v6.53.0
Problem
Unfortunately, datepicker bug fix attempt #2 (#6096) caused an actual incident due to incorrect date validation for the pastOnlyValidator (post-mortem).
Solution
For bug caused by #6096 - Restore original date validators.
Breaking Changes
Improvements:
Bug Fixes:
zonedTimeToUTC
was converting the timings to UTC and thus the actual date being referred to will not be preserved for respondents in negative UTC timezones. ImplementednormalizeDateToUtc
to ensure the actual date numbers are are preserved.Date.UTC
instead of converting time usingzonedTimeToUTC
(which we were using wrong anyway, as pointed out by @darrelhong in fix: date picker calendar select correct date in negative UTC offset timezones #5731)Before & After Screenshots
BEFORE:
Screen.Recording.2023-03-31.at.3.18.31.AM.mov
AFTER:
Disallow past dates:
Screen.Recording.2023-04-13.at.2.48.49.PM.mov
Disallow future dates:
Screen.Recording.2023-04-13.at.5.08.17.PM.mov
Custom date range:
Screen.Recording.2023-04-13.at.5.11.57.PM.mov
Tests
To ensure that all our bases are covered, try to test the most extreme timezones. Here are the suggested timezones:
Preparation:
For the tests below, timezones A and B refer to the positive and negative timezones mentioned above, in any order.
i) Ensure that date picker for date field with "Disallow past dates" option exhibits expected behaviour:
ii) Ensure that date picker for date field with "Disallow future dates" option exhibits expected behaviour:
iii) Ensure that date picker for date field with "Custom date range" option exhibits expected behaviour:
iv) Ensure that email mode forms with date field still work:
Note: Here's how to set your Mac's timezone.
Design/ product question: Should "Disallow past dates" and "Disallow future dates" be taking the past / future based on the admins' timezone, specified timezone or the users' timezone? Also, even when we have decided on the previous question, does it even make sense if the concept of time is not considered? E.g. if the recurring event I want to organise is at 10am, our date picker won't be able to know that so if we have a timezone in mind, it won't "filter" properly. Currently, it's simply implemented based on the users' timezone so its not disorienting.