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

オープン
#4,057 コメント 3 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@mathuryashash がすでに取り組んでいます。

2026年12月3日 から。

  • #4058 @mathuryashash による — オープン

評価

この issue はまだ評価されていません。

説明

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.
主要言語
TypeScript
スター
246
フォーク
436
平均マージ
9時間 33分
マージ済み PR(30日)
213

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Priyanshu-byte-coder/devtrack のほかの issue

Priyanshu-byte-coder/devtrack の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。