Skip to content

Commit 3bdbc79

Browse files
committed
Fix Infinity validation in daysBetween
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.
1 parent 7b65652 commit 3bdbc79

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

common/src/util/reddit-freebuff-retention.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type FreebuffRedditConversionPlan = {
1414
function daysBetween(fromDateKey: string, toDateKey: string): number {
1515
const from = new Date(`${fromDateKey}T00:00:00.000Z`).getTime()
1616
const to = new Date(`${toDateKey}T00:00:00.000Z`).getTime()
17-
if (Number.isNaN(from) || Number.isNaN(to)) {
17+
if (!Number.isFinite(from) || !Number.isFinite(to)) {
1818
throw new Error(`Invalid date key range: ${fromDateKey} -> ${toDateKey}`)
1919
}
2020
return Math.round((to - from) / DAY_MS)

0 commit comments

Comments
 (0)