Fix Infinity validation in daysBetween - #1244
Conversation
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.
|
Good catch and a minimal, focused fix. That said, since Overall this is small enough and correct enough to be worth porting as-is, though a quick test addition would make it airtight. |
Overview
Fix Infinity validation in the
daysBetweenfunction incommon/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, causingMath.round(Infinity)to return Infinity.Fix
Changed
Number.isNaN()toNumber.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 validationScope
This change only touches
common/which is an approved contribution area per the Contributing Guide.