Skip to content

fix(date-range): compute the default range lazily to avoid a stale year#4842

Merged
JhaSourav07 merged 1 commit into
JhaSourav07:mainfrom
Anexus5919:fix/date-range-lazy-default
Jun 12, 2026
Merged

fix(date-range): compute the default range lazily to avoid a stale year#4842
JhaSourav07 merged 1 commit into
JhaSourav07:mainfrom
Anexus5919:fix/date-range-lazy-default

Conversation

@Anexus5919

Copy link
Copy Markdown
Contributor

Description

Fixes #4841

utils/dateRange.ts exposed the fallback range as a constant whose year was captured once at module load (new Date().getUTCFullYear() inside DEFAULT_DATE_RANGE). That value goes stale after a New Year rollover in a long-lived process, and formatDateRange returned it for missing or invalid years, inheriting the staleness.

This change replaces the constant with a lazy function getDefaultDateRange() that computes the current-year range each time it is called, so the value is always correct. formatDateRange now calls getDefaultDateRange() for its empty and invalid-year fallbacks. The DateRange interface was moved above the function it types.

DEFAULT_DATE_RANGE had no production callers (only the module and its test referenced it), so converting it to a function is safe. The test that read the old constant now calls getDefaultDateRange(), and a new test mocks the system clock across a year boundary (2030 then 2031) to confirm the range is computed lazily rather than captured once.

Pillar

  • Pillar 1: New Theme Design
  • Pillar 2: Geometric SVG Improvement
  • Pillar 3: Timezone Logic Optimization
  • Other (bug fix, refactoring, docs)

Visual Preview

Not applicable. Internal date-range utility change.

Checklist before requesting a review:

  • I have read the CONTRIBUTING.md file.
  • I have tested these changes locally (all utils/dateRange.test.ts tests pass, 14 tests including the new lazy-evaluation test; tsc --noEmit clean for this file).
  • 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. (No 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. (Not applicable, utility change.)
  • (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.

@vercel

vercel Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

@Anexus5919 is attempting to deploy a commit to the jhasourav07's projects Team on Vercel.

A member of the Team first needs to authorize it.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@github-actions github-actions Bot added the type:bug Something isn't working as expected label Jun 8, 2026
@Aamod-Dev Aamod-Dev added level:intermediate Moderate complexity tasks quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. GSSoC 2026 mentor:Aamod007 labels Jun 11, 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.

Great logical fix! Lazily computing the default date range prevents stale year bugs when the application instance runs across New Year's boundaries. Approving!

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

Thanks for the PR. I've reviewed the changes and they look good to me.

I'm happy to approve this. Great job!

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

Thanks for the contribution. I went through the changes and the overall approach looks good, but there are a few issues that should be addressed before this can be merged. Most of the concerns are related to correctness and maintainability.

  • There are merge conflicts with the base branch. Please resolve them to ensure existing functionality isn't broken.

Once these issues are addressed, I'll be happy to take another look. Thanks again for the contribution.

@Anexus5919 Anexus5919 force-pushed the fix/date-range-lazy-default branch from fd898d4 to 2951fd2 Compare June 12, 2026 05:10
@Anexus5919

Copy link
Copy Markdown
Contributor Author

@Aamod007 @JhaSourav07
I have rebased this branch onto the latest main and resolved the merge conflict in utils/dateRange.ts.

Could you please take another look when you get a chance? Thanks!

@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label Jun 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚨 Hey @Anexus5919, the CI Pipeline is failing on this PR and it has been marked as status:blocked.

Please fix the issues before this can be reviewed. Here's how:

1. Run checks locally before pushing:

npm run format:check   # Check Prettier formatting
npm run lint           # Run ESLint
npm run typecheck      # TypeScript type check
npm run test           # Run unit tests (Vitest)
npm run build          # Verify production build passes

2. Auto-fix common issues:

npm run format         # Auto-fix formatting with Prettier
npm run lint -- --fix  # Auto-fix lint errors where possible

3. Check the full failure log here:
👉 View CI Run

Once you push a fix and the CI passes, the status:blocked label will be removed automatically. 💪

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

Thanks for the contribution. The overall approach looks good, but the CI pipeline is currently failing. Please run the checks (like npm run format, npm run lint, and npm run test) locally to identify and fix the issues. Let me know once it's green!

@github-actions github-actions Bot removed the status:blocked This PR is blocked due to a failing CI check. label Jun 12, 2026
@Anexus5919 Anexus5919 force-pushed the fix/date-range-lazy-default branch from 4ede7fe to d27b5b7 Compare June 12, 2026 08:51
@Anexus5919

Copy link
Copy Markdown
Contributor Author

@Aamod007 Done. Please have a re-review on this. Thanks!

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

Thanks for fixing the CI pipeline! Approving.

@JhaSourav07 JhaSourav07 added the gssoc:approved PR has been reviewed and accepted for valid contribution points label Jun 12, 2026
@JhaSourav07 JhaSourav07 merged commit eae05ee into JhaSourav07:main Jun 12, 2026
5 of 6 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Congratulations @Anexus5919! 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 this to the GSSoC 2026 milestone Jun 12, 2026
@JhaSourav07 JhaSourav07 added gssoc:approved PR has been reviewed and accepted for valid contribution points and removed gssoc:approved PR has been reviewed and accepted for valid contribution points labels Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved PR has been reviewed and accepted for valid contribution points gssoc:needs-rebase 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: DEFAULT_DATE_RANGE captures the year once at module load and goes stale after New Year

3 participants