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

Đang mở
#4,057 3 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@mathuryashash đang làm issue này rồi.

Từ ngày 3/12/2026.

  • #4058 của @mathuryashash — đang mở

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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.
Ngôn ngữ chính
TypeScript
Star
246
Fork
436
Merge trung bình
9 giờ 33 phút
Pull request đã merge (30 ngày)
213

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Priyanshu-byte-coder/devtrack

Tất cả issue của Priyanshu-byte-coder/devtrack

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.