Skip to content

Streak calculation disagrees between Home/Statistics and Insights #7

Description

@astraedus

Found during store-screenshot QA on v2.6.0 (Pixel 3, 90 consecutive days of imported demo data):

  • Home and Statistics show: 61-day streak / best 61
  • Insights shows: 90 days current streak / longest 90 / 90 entries logged

Same database, same days, two streak implementations disagree. Likely suspect: one path day-keys via SQL date functions and the other via localDateString() (SQL day-keying is the documented anti-pattern in this repo, see CLAUDE.md / frontend/databases). The demo data also surfaced a possible contributing artifact: frontend/scripts/make-demo-data.js can emit a 1-day gap ~2 months back when the generating laptop's timezone differs from the device's (local-noon pinning edge), the 61 vs 90 split point coincides with it. The Insights implementation appears to bridge the gap; Home/Stats does not (or vice versa, needs tracing).

Fix should:

  1. Unify streak computation into ONE shared, unit-tested transform used by all three surfaces.
  2. Decide the honest semantic for a 1-day gap (streak broken) and make all surfaces agree.
  3. Add a regression test with a gapped dataset.
  4. Optionally fix the TZ edge in make-demo-data.js.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions