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

Open
#4,057 3 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@mathuryashash is already working on this.

Since Dec 3, 2026.

  • #4058 by @mathuryashash — open

Assessment

This issue has not been assessed yet.

Description

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.
Dominant language
TypeScript
Stars
246
Forks
436
Avg merge
9h 33m
Merged PRs (30d)
213

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Priyanshu-byte-coder/devtrack

All issues in Priyanshu-byte-coder/devtrack

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.