fix(validations): use UTC year for streak/wrapped year validation upper bound#6246
Conversation
…er bound Replaces new Date().getFullYear() (server-local time) with new Date().getUTCFullYear() in both streakParamsSchema and wrappedParamsSchema year validation, removing server-timezone dependency from the upper bound check. Also updates the corresponding test file (lib/validations.year.test.ts) to compute CURRENT_YEAR via getUTCFullYear() for consistency with the schema's new behaviour. Closes JhaSourav07#6244
|
Someone is attempting to deploy a commit to the jhasourav07's projects Team on Vercel. A member of the Team first needs to authorize it. |
📦 Next.js Bundle Size Report (Gzipped Sizes)✨ No significant bundle size changes detected. 📊 Summary of Totals
|
Aamod-Dev
left a comment
There was a problem hiding this comment.
Using getUTCFullYear() instead of getFullYear() in lib/validations.ts is a critical fix to ensure we don't have timezone-dependent validation failures around the New Year boundary. The update to lib/validations.year.test.ts to reflect this change is also perfectly executed. Approved!
|
🎉 Congratulations @nishupr! Your PR has been successfully merged. 🚀 Thank you for contributing to CommitPulse. Your work helps us build a better tool for the community.
Keep building! 💻✨ |
Description
Fixes #6244
In
lib/validations.ts, bothstreakParamsSchemaandwrappedParamsSchemavalidate theyearquery parameter's upper bound using:Problem with the old approach:
new Date().getFullYear()returns the year in the server's local timezone, not UTCapp/api/wrapped/route.ts(bug: wrapped route calculates default year using server timezone instead of user's tz parameter #6242), where the default year calculation was changed to avoid server-local-time dependencyWhat this PR does:
new Date().getFullYear()withnew Date().getUTCFullYear()in bothstreakParamsSchemaandwrappedParamsSchemavalidation refinementslib/validations.year.test.tsto computeCURRENT_YEARviagetUTCFullYear()for consistency, ensuring tests remain accurate regardless of the test runner's local timezoneNote: The
refine()callback only receives the field value, not other parsed fields liketz, so full per-user timezone-aware validation would requiresuperRefine. Switching to UTC removes the core server-local-time dependency, which was the primary issue.After:
Pillar
Visual Preview
No visual changes — this is a validation correctness fix.
Checklist before requesting a review:
CONTRIBUTING.mdfile.localhost:3000/api/streak?user=YOUR_USERNAME).npm run formatandnpm run lintlocally and resolved all errors (CI will fail otherwise).feat(themes): ...,fix(calculate): ...).README.mdif I added a new theme or URL parameter.