Skip to content

Fix Infinity validation in daysBetween - #1244

Open
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/reddit-retention-infinity-validation
Open

Fix Infinity validation in daysBetween#1244
pavankumar-vh wants to merge 1 commit into
CodebuffAI:mainfrom
pavankumar-vh:fix/reddit-retention-infinity-validation

Conversation

@pavankumar-vh

Copy link
Copy Markdown

Overview

Fix Infinity validation in the daysBetween function in common/src/util/reddit-freebuff-retention.ts.

Bug Description

The function only checked for NaN, not Infinity. If the date string represented an extreme date, getTime() could return Infinity, causing Math.round(Infinity) to return Infinity.

Fix

Changed Number.isNaN() to Number.isFinite() to catch both NaN and Infinity.

Testing

No existing tests for this function, but the fix prevents incorrect behavior with extreme dates.

Files Changed

  • common/src/util/reddit-freebuff-retention.ts - Added Infinity validation

Scope

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

The function only checked for NaN, not Infinity. If the date string represented
an extreme date, getTime() could return Infinity, causing Math.round(Infinity)
to return Infinity.

Changed Number.isNaN() to Number.isFinite() to catch both NaN and Infinity.
@codebuff-team

Copy link
Copy Markdown
Contributor

Good catch and a minimal, focused fix. Date.getTime() for valid but extreme date strings can produce Infinity/-Infinity rather than NaN (e.g. new Date('275760-09-14').getTime() overflow behavior in some engines), and Number.isFinite correctly subsumes the NaN check since NaN is not finite either. The change is a strict superset of the prior validation, so no regression risk.

That said, since fromDateKey/toDateKey are described as date keys (likely YYYY-MM-DD from a bounded practical range), it would strengthen this PR to include a one-line test in the corresponding test file confirming both the NaN case (invalid string) and an out-of-range date still throw. There's no test file touched here, and the repo would likely expect one for a validation-logic change like this, even if small.

Overall this is small enough and correct enough to be worth porting as-is, though a quick test addition would make it airtight.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree labels Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants