From 39a0a68af3b730524d0b529b89175e2629fb6c73 Mon Sep 17 00:00:00 2001 From: Pavan Kumar VH Date: Thu, 3 Sep 2026 11:24:31 +0530 Subject: [PATCH] Improve null handling in getNextQuotaReset 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. --- common/src/util/dates.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/src/util/dates.ts b/common/src/util/dates.ts index 57096e324a..0dc7af396c 100644 --- a/common/src/util/dates.ts +++ b/common/src/util/dates.ts @@ -9,7 +9,12 @@ */ export const getNextQuotaReset = (referenceDate: Date | null): Date => { const now = new Date() - let nextMonth = new Date(referenceDate ?? now) + if (referenceDate === null) { + const next = new Date(now) + next.setMonth(next.getMonth() + 1) + return next + } + let nextMonth = new Date(referenceDate) while (nextMonth <= now) { nextMonth.setMonth(nextMonth.getMonth() + 1) }