Skip to content

fix(wrapped): use tz parameter for default year calculation#6243

Merged
JhaSourav07 merged 1 commit into
JhaSourav07:mainfrom
nishupr:fix/wrapped-timezone-year-6242
Jun 21, 2026
Merged

fix(wrapped): use tz parameter for default year calculation#6243
JhaSourav07 merged 1 commit into
JhaSourav07:mainfrom
nishupr:fix/wrapped-timezone-year-6242

Conversation

@nishupr

@nishupr nishupr commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #6242

In app/api/wrapped/route.ts, the default year (used when customYear is not provided) was calculated using the server's local timezone:

const year = customYear || new Date().getFullYear().toString();

However, the same route already accepts and uses a tz parameter for fetching timezone-aware wrapped stats elsewhere in the handler:

const wrappedStats = tz
  ? await getWrappedData(user, year, { bypassCache: shouldBypassCache }, tz)
  : await getWrappedData(user, year, { bypassCache: shouldBypassCache });

Problem with the old approach:

  • A user near a year boundary (e.g. New Year's Eve/Day) in a timezone different from the server could get the wrong default year
  • For example, if the server is on UTC and a user is in UTC+13 (New Zealand), the server might still report the previous year while the user has already entered the new year locally — or vice versa
  • This mirrors a pattern already correctly handled elsewhere in the codebase — app/api/streak/route.ts uses Intl.DateTimeFormat with an explicit timezone for the equivalent calculation

What this PR does:

  • Uses the existing tz parameter (when provided) to compute the default year via Intl.DateTimeFormat, consistent with app/api/streak/route.ts
  • Falls back to new Date().getFullYear() only when no tz is supplied
  • No changes to the cache or data-fetching logic — only the year calculation is timezone-aware now

After:

const year =
  customYear ||
  (tz
    ? new Intl.DateTimeFormat('en-CA', { timeZone: tz, year: 'numeric' }).format(new Date())
    : new Date().getFullYear().toString());

Pillar

  • 🎨 Pillar 1 — New Theme Design
  • 📐 Pillar 2 — Geometric SVG Improvement
  • 🕐 Pillar 3 — Timezone Logic Optimization
  • 🛠️ Other (Bug fix, refactoring, docs)

Visual Preview

No visual changes — this is a timezone correctness fix.

Checklist before requesting a review:

  • I have read the CONTRIBUTING.md file.
  • I have tested these changes locally (localhost:3000/api/streak?user=YOUR_USERNAME).
  • I have run npm run format and npm run lint locally and resolved all errors (CI will fail otherwise).
  • My commits follow the Conventional Commits format (e.g., feat(themes): ..., fix(calculate): ...).
  • I have updated README.md if I added a new theme or URL parameter.
  • I have started the repo.
  • I have made sure that i have only one commit to merge in this PR.
  • The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts).
  • (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.

The default year (when customYear is not provided) was calculated
using the server's local timezone via new Date().getFullYear(),
even though the route already accepts and uses a tz parameter for
timezone-aware data fetching elsewhere in the same handler.

This caused a mismatch near year boundaries for users in timezones
different from the server. Now uses Intl.DateTimeFormat with the
provided tz, consistent with the pattern in app/api/streak/route.ts.

Closes JhaSourav07#6242
@vercel

vercel Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Size Report (Gzipped Sizes)

✨ No significant bundle size changes detected.

📊 Summary of Totals

Category PR Size Base Size Difference
Total JS 3697.00 KB 3697.00 KB 0 B
Total CSS 296.58 KB 296.58 KB 0 B

@Aamod-Dev Aamod-Dev added GSSoC 2026 mentor:Aamod007 level:intermediate Moderate complexity tasks quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. bug Something isn't working labels Jun 21, 2026

@Aamod-Dev Aamod-Dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Excellent fix. Falling back to the server's local timezone instead of the user's tz parameter for the default year calculation was a subtle bug. Using Intl.DateTimeFormat in app/api/wrapped/route.ts is the correct approach to maintain cross-timezone accuracy near the New Year boundary. Approved!

@JhaSourav07 JhaSourav07 added the gssoc:approved PR has been reviewed and accepted for valid contribution points label Jun 21, 2026
@JhaSourav07 JhaSourav07 merged commit cdfd6cc into JhaSourav07:main Jun 21, 2026
10 of 11 checks passed
@github-actions github-actions Bot added this to the GSSoC 2026 milestone Jun 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🎉 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.

⚠️ Important for GSSoC Contributors:
You are strictly advised to join our Discord Server as it is mandatory for all GSSoC participants. All important announcements, point claims, and community discussions happen there.

Keep building! 💻✨

@github-actions github-actions Bot added the type:bug Something isn't working as expected label Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working gssoc:approved PR has been reviewed and accepted for valid contribution points GSSoC 2026 level:intermediate Moderate complexity tasks mentor:Aamod007 quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. type:bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: wrapped route calculates default year using server timezone instead of user's tz parameter

3 participants