[BUG] Consistency score uses the server clock instead of the user's time zone for weekly consistency and the monthly trend

Aperta
#4,057 3 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@mathuryashash ci sta già lavorando.

Dal 3/12/2026.

  • #4058 di @mathuryashash — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

status:assigned
What happened?

calculateConsistencyScore(activeDates, timeZone) in src/lib/consistency-score.ts works out "today" and the streak in the user's time zone, but computeWeeklyConsistency and computeMonthlyTrend ignore the zone and call new Date() on the server clock. The route already buckets active dates in the user's zone, so the two sides disagree around midnight at the Sunday/Monday and month boundaries.

For a user whose local date is already Monday (or the 1st) while the server is still on Sunday (or the last day of the month):

  • activity from today is not counted in the current week, so weekly consistency is one week short and the score drops;
  • the newest bar in the monthly trend is labelled with the previous month and shows 0 active days.

With the server on UTC this hits every user ahead of UTC (all of Asia and Australia, for example) for a few hours at each boundary.

Steps to reproduce
  1. Fake the clock to 2024-06-16T22:00Z (already Monday 17 June in Pacific/Kiritimati).
  2. Call calculateConsistencyScore(new Set(["2024-06-17"]), "Pacific/Kiritimati").
  3. weeklyConsistency is 0. Expected 8 (1 of 12 weeks).
  4. With the clock at 2024-06-30T20:00Z and activity on "2024-07-01" for the same zone, monthlyTrend[5] is { month: "Jun 2024", activeDays: 0 }. Expected { month: "Jul 2024", activeDays: 1 }.
Where is it?

Streak and activity

Where did you see it?

Local development

Browser and device

Not browser-specific (server-side calculation in /api/metrics/consistency-score).

Screenshots, console errors or logs
AssertionError: expected +0 to be 8
AssertionError: expected { month: 'Jun 2024', activeDays: +0 } to deeply equal { month: 'Jul 2024', activeDays: 1 }
Proposed fix

Pass the zone-aware today string that calculateConsistencyScore already computes into both helpers, and derive the current week start and the six months from it instead of new Date(). Add vitest cases for a zone ahead of and a zone behind the server, so the tests do not depend on the machine's own zone.

Want to fix it?
  • I'd like to work on this.
Lingua principale
TypeScript
Stelle
246
Fork
436
Merge medio
9h 33m
PR unite (30g)
213

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Priyanshu-byte-coder/devtrack

Tutte le issue di Priyanshu-byte-coder/devtrack

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.