Skip to content

Improve null handling in getNextQuotaReset - #1232

Open
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/dates-null-validation
Open

Improve null handling in getNextQuotaReset#1232
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/dates-null-validation

Conversation

@pavankumar-vh

Copy link
Copy Markdown

Overview

Improve null handling in the getNextQuotaReset function in common/src/util/dates.ts.

Bug Description

The original code used referenceDate ?? now which meant when referenceDate was null, it created a new Date from now, then the while loop would immediately add a month since nextMonth <= now would be true (they're equal).

This is inefficient and the intent is unclear.

Fix

Made the null case explicit:

  • When referenceDate is null, return next month from now directly
  • When referenceDate is provided, start from that date and add months until it's in the future

Testing

No existing tests for this function, but the fix improves clarity and efficiency.

Files Changed

  • common/src/util/dates.ts - Improved null handling

Scope

This change only touches common/ which is an approved contribution area per the Contributing Guide.

The original code used 'referenceDate ?? now' which meant when referenceDate
was null, it created a new Date from now, then the while loop would immediately
add a month since nextMonth <= now would be true (they're equal).

This is inefficient and the intent is unclear. Made the null case explicit:
when referenceDate is null, return next month from now directly.

When referenceDate is provided, start from that date and add months until
it's in the future, which is the original behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant