[BUG] Streak uses the UTC date instead of the user's local date

Aperta Adatta ai principianti
#116 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react-native, typescript
Ambito
mobile

Direzione di ricerca

Inizia in src/utils/stats.ts, da updateStreak, poi confronta la gestione delle date con getWeekId in src/types/weekUtils.ts. Esegui i test esistenti sulle streak, se presenti, e verifica il comportamento intorno alla mezzanotte locale in UTC+2 e a ovest di UTC. Il lavoro è concluso quando le date delle streak usano il calendario locale e il formato memorizzato YYYY-MM-DD rimane invariato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug gamification good first issue

Description

updateStreak in src/utils/stats.ts computes "today" and "yesterday" from new Date().toISOString(), which gives the UTC calendar date. The rest of the planner (week ids, days) uses the local date (src/types/weekUtils.ts).

For users outside UTC, activity near midnight is recorded on the wrong day:

  • In UTC+2 (e.g. Central Europe in summer), completing a block at 00:30 local time on Tuesday stores lastActiveDate as Monday.
  • Two activities at 23:30 Monday and 00:30 Tuesday local time can land on the same UTC date, so the streak is not incremented even though the user was active on two consecutive local days.
  • West of UTC the opposite happens in the evening.

Steps to reproduce

  1. Set the device timezone to UTC+2.
  2. Complete a block at 00:30 local time.
  3. lastActiveDate (AsyncStorage @levelup/last_active) holds the previous day's date.

Expected behavior

Streak days follow the user's local calendar, consistent with the planner weeks.

Suggested fix

Build the date string from local fields (getFullYear(), getMonth(), getDate()), as getWeekId already does, and compute "yesterday" the same way. Existing users' stored lastActiveDate values stay valid (same YYYY-MM-DD format).

Found while writing tests; drafted with the help of Claude Code.

Lingua principale
TypeScript
Stelle
4
Fork
4
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

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 GiZano/LevelUp

Tutte le issue di GiZano/LevelUp

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.