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

chore: fix traffic data timezone visualization issue with getUTCDate #9110

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/hooks/useTrafficData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const toChartData = (

for (const dayKey in item.days) {
const day = item.days[dayKey];
const dayNum = new Date(Date.parse(day.day)).getDate();
const dayNum = new Date(Date.parse(day.day)).getUTCDate();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add a test for the function generating those dates that fails with previous code and succeeds with the new one

Copy link
Contributor

Choose a reason for hiding this comment

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

He showed me the test but it needs to run vite with a different timezone

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, yep fully onboard with that @kwasniew - but I'm yet to find a good way to have a committable repro test for this :( Looking into spoofing timezones and such, but doesn't bite.

Copy link
Contributor

Choose a reason for hiding this comment

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

may not be worth the effort. ideally before the test we should change the timezone and reset to original value afterward.

Copy link
Contributor

Choose a reason for hiding this comment

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

another option would be to avoid overriding the timezone in the tested method explicitly

Copy link
Contributor

@kwasniew kwasniew Jan 17, 2025

Choose a reason for hiding this comment

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

sth like this. haven't checked if it works

const originalTimeZone = process.env.TZ;
beforeEach(() => {
  // Set the timezone to the desired value
  process.env.TZ = 'America/New_York';
});

afterEach(() => {
  // Reset the timezone to the original value
  process.env.TZ = originalTimeZone;
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying that but can't get it to "bite" unfortunately

daysRec[`d${dayNum}`] = day.trafficTypes[0].count;
}
const epInfo = endpointsInfo[item.apiPath];
Expand Down
Loading