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

Conversation

daveleek
Copy link
Contributor

Dates are hard. For a lot of timezones new Date(Date.parse('2025-01-01T00:00:00.000Z')).getDate() could be returned as 31 and not 1

By using getUTCDate instead we now adjust accordingly and return the right day number.

Copy link

vercel bot commented Jan 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2025 8:31am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Jan 17, 2025 8:31am

Copy link
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

@@ -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

@daveleek daveleek merged commit 2d340f6 into main Jan 17, 2025
13 checks passed
@daveleek daveleek deleted the chore/fix-traffic-data-timezone-visualization-issue branch January 17, 2025 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants