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

fix(vizBuilder): RN-1054: picks wrong date #5447

Merged
merged 43 commits into from
Apr 4, 2024
Merged

Conversation

jaskfla
Copy link
Contributor

@jaskfla jaskfla commented Feb 23, 2024

Issue RN-1054: Fix Viz Buidler Date Picker behaviour

Changes

Fixes behaviour in Viz Builder where date picker would select a date and time (with a deterministic-but-unpredictable time), which resulted in unexpected query results

The nitty-gritty
  • Bug was caused by the combination of Yup’s coercion when validating dates in schemas with JavaScript’s sometimes unpredictable date parsing behaviour.
  • Previously we were calling the fetchReportPreviewData endpoint with full ISO timestamps (date and time) in Zulu time, usually converted from whatever the user’s browser’s local time was (this behaviour seems to vary between browsers/runtime environments).
  • Data would get turned into string in front-end, then coerced into Date object in back-end (which introduces timezone conversion issues), and back into string for DataTableService’s consumption.
  • Now kept as a string throughout.

jaskfla added 3 commits March 7, 2024 10:30
Importing from `tsutils` to front-end packages is problematic
Copy link
Contributor

@alexd-bes alexd-bes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, looks great. I have a couple of pedantic suggestions, but I'm happy to pre-approve

@jaskfla jaskfla marked this pull request as ready for review March 10, 2024 23:09
@jaskfla jaskfla changed the title RN-1054: Fix VizBuidler Date Picker behaviour fix: RN-1054: VizBuidler date picker Apr 2, 2024
@jaskfla jaskfla changed the title fix: RN-1054: VizBuidler date picker fix: RN-1054: VizBuilder date picker Apr 2, 2024
merge latest dev before testing
@jaskfla jaskfla changed the title fix: RN-1054: VizBuilder date picker fix(vizBuilder): RN-1054: picks wrong date Apr 2, 2024
Comment on lines 44 to 61
/**
* When you select a date in the date picker (either with the interactive calendar or by inserting
* a valid date string), the picker actually selects a specific moment in time on that date with
* the normal, millisecond granularity of a Date object. The time of day it selects is the current
* local time on the system where VizBuilder is running.
*
* When inputting the date, the date picker interprets it in the user’s time zone. Under the hood,
* this is converted to UTC. But since we only need day-level granularity, this timezone
* conversion can make the date picker select a date different from what the user input (±1 day)
* when {@link converDateToIsoString} discards the timestamp.
*
* This helper function accounts for that discrepancy.
*
* @param date A valid date object
* @returns {Date}
*/
const shiftEpoch = date =>
new Date(date.setMinutes(date.getMinutes() - date.getTimezoneOffset()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexd-bes This is the hacky fix I mentioned in stand-up this morning. Easy enough to understand, but you can imagine why I’m not happy about it 😅

Andrew went to the trouble of testing at multiple times throughout the day and it does seem to work, though; so it’s currently marked as test passed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is probably fine - as you say, it's a very specific case and it's an old install of datepicker which may get rejigged anyway, so if it works it's all good

@jaskfla jaskfla enabled auto-merge (squash) April 4, 2024 00:43
@jaskfla jaskfla merged commit f64998d into dev Apr 4, 2024
43 checks passed
@jaskfla jaskfla deleted the rn-1054-vizbuilder-datepicker branch April 4, 2024 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants