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