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

Abierto
#4,057 3 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@mathuryashash ya está trabajando en esto.

Desde el 3/12/2026.

  • #4058 de @mathuryashash — abierto

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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.
Lenguaje dominante
TypeScript
Estrellas
246
Forks
436
Merge medio
9 h 33 min
PR fusionados (30 d)
213

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Priyanshu-byte-coder/devtrack

Todos los issues de Priyanshu-byte-coder/devtrack

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.