From 392bd6416e45c23f16f2c9fd05d2bfeed350d909 Mon Sep 17 00:00:00 2001 From: Spencer Flagg Date: Sat, 25 Apr 2026 13:29:43 +0200 Subject: [PATCH] fix: current streak should not reset to zero before today's check-in MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit currentStreak() was starting its backward walk from today, so if the user hadn't checked in yet today the first lookup missed and it returned 0 — even with a perfect streak on previous days. Now when today's entry is absent and the goal is still active, the count starts from yesterday instead. Once the goal window has closed the original end-of-window anchor is preserved. --- frontend/public/js/stats.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/public/js/stats.js b/frontend/public/js/stats.js index 97bf442..75f94c8 100644 --- a/frontend/public/js/stats.js +++ b/frontend/public/js/stats.js @@ -56,9 +56,15 @@ export function completedSet(completions, user, goalId) { */ export function currentStreak(completedSetForUser, goal, refISO = todayISO()) { const start = goal.start_date; - const end = clampWindowEnd(goal, refISO); + let end = clampWindowEnd(goal, refISO); if (refISO < start) return 0; + // If today isn't completed yet and the goal is still active, + // start from yesterday — the day isn't over so don't break the streak. + if (end === refISO && !completedSetForUser.has(end)) { + end = addDays(end, -1); + } + let cur = end; let n = 0; while (cur >= start && completedSetForUser.has(cur)) {