[BUG] Consistency score uses the server clock instead of the user's time zone for weekly consistency and the monthly trend
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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.
- 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
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Priyanshu-byte-coder/devtrack
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Priyanshu-byte-coder/devtrack#4067 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Priyanshu-byte-coder/devtrack#4066 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Webhook manager: replace the browser confirm() dialogs with ConfirmModalCó thể đã có người làm @Nandaninaulaa đã nhận 4 ngày trước. Đang mởgood first issue level 1 level:beginner status:assigned type:design
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
Priyanshu-byte-coder/devtrack#3889 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Goals form: square arcade buttons for recurrence, Create goal and RefreshCó thể đã có người làm @KartikeyG-world đã nhận 4 ngày trước. Đang mởgood first issue level 1 level:beginner status:assigned type:design
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Priyanshu-byte-coder/devtrack#3877 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Goals: the error banner and the "No goals yet" hint show at the same timeCó thể đã có người làm @KartikeyG-world đã nhận 4 ngày trước. Đang mởgood first issue level 1 level:beginner status:assigned type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Priyanshu-byte-coder/devtrack#3872 · 6 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Priyanshu-byte-coder/devtrack
Issue tương tự
-
提出物確認の詳細で状態バッジの重複と期限切れの欠落を直すĐang mởCodex使用可 かんたん コード
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ryuki-moro/Nicomaru#348 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
area-integrations
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày