[BUG] Consistency score uses the server clock instead of the user's time zone for weekly consistency and the monthly trend
I maintainer di solito rispondono entro 1 giorno
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
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
- Fake the clock to
2024-06-16T22:00Z(already Monday 17 June inPacific/Kiritimati). - Call
calculateConsistencyScore(new Set(["2024-06-17"]), "Pacific/Kiritimati"). weeklyConsistencyis 0. Expected 8 (1 of 12 weeks).- With the clock at
2024-06-30T20:00Zand 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
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Priyanshu-byte-coder/devtrack
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Priyanshu-byte-coder/devtrack#4067 ·
I maintainer di solito rispondono entro 1 giorno
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
Priyanshu-byte-coder/devtrack#4066 ·
I maintainer di solito rispondono entro 1 giorno
-
Webhook manager: replace the browser confirm() dialogs with ConfirmModalForse già presa @Nandaninaulaa l’ha presa 4 giorni fa. Apertagood first issue level 1 level:beginner status:assigned type:design
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
Priyanshu-byte-coder/devtrack#3889 · 4 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Goals form: square arcade buttons for recurrence, Create goal and RefreshForse già presa @KartikeyG-world l’ha presa 4 giorni fa. Apertagood first issue level 1 level:beginner status:assigned type:design
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
Priyanshu-byte-coder/devtrack#3877 · 4 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Goals: the error banner and the "No goals yet" hint show at the same timeForse già presa @KartikeyG-world l’ha presa 4 giorni fa. Apertagood first issue level 1 level:beginner status:assigned type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
Priyanshu-byte-coder/devtrack#3872 · 6 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Priyanshu-byte-coder/devtrack
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
makecindy/cindy#15342 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
kwitsch/claude-code-plugin-tooling#219 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
no-repo-link tool-submission
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 74/100
BraveOPotato/NoSignups#2618 ·
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100