Skip to content

fix(dashboard): make activity date keys/range independent of server TZ#73

Open
Chzhqv wants to merge 1 commit into
TemaDeveloper:mainfrom
Chzhqv:fix/dashboard-activity-timezone-keys
Open

fix(dashboard): make activity date keys/range independent of server TZ#73
Chzhqv wants to merge 1 commit into
TemaDeveloper:mainfrom
Chzhqv:fix/dashboard-activity-timezone-keys

Conversation

@Chzhqv

@Chzhqv Chzhqv commented Jul 7, 2026

Copy link
Copy Markdown

Summary

  • Date-only fields are stored as UTC midnight of the intended calendar day (e.g. "2026-01-15" parses to 2026-01-15T00:00:00.000Z). The dashboard activity route read these back with date-fns' format()/startOfMonth()/endOfMonth(), which use the server process's local timezone — on a server not running in UTC, this could both shift an entry onto the adjacent calendar day and query the wrong month's range entirely.
  • Extracted toDateKey/utcMonthRange into src/lib/date-key.ts (UTC-getter based, independent of server TZ) and use them in the activity route.

Test plan

  • Reproduced live on this machine's own EST dev server (a real negative-UTC-offset environment, not simulated) — an expense dated "2026-01-15" was invisible in the January activity map entirely before the range fix (querying essentially December's UTC range instead), and would have appeared under the wrong key "2026-01-14" once only the range was fixed; with both fixes it correctly appears under "2026-01-15"
  • Added regression tests (lib/__tests__/date-key.test.ts) that flip process.env.TZ across the assertion (EST, UTC+14, UTC) and confirm the UTC-anchored result stays correct — confirmed they fail against the old date-fns-based implementation and pass against the fix
  • pnpm lint, tsc --noEmit, full vitest run (558/558) all pass

Fixes #23

Date-only fields are stored as UTC midnight of the intended calendar
day (e.g. "2026-01-15" parses to 2026-01-15T00:00:00.000Z). The
activity route read these back with date-fns' format()/startOfMonth()/
endOfMonth(), which use the server process's local timezone — on a
server not running in UTC, this could both shift an entry onto the
adjacent calendar day and query the wrong month's range entirely.

Extracted toDateKey/utcMonthRange into src/lib/date-key.ts (UTC-getter
based, so the result no longer depends on server TZ) and use them in
the activity route.

Verified live: reproduced on this machine's own EST dev server (a
real negative-UTC-offset environment) — an expense dated "2026-01-15"
was previously invisible in the January activity map entirely (wrong
month range) and would have kept appearing under "2026-01-14" once
the range was fixed (day-key mismatch); with both fixes it correctly
appears under "2026-01-15". Added regression tests that flip
process.env.TZ across the fetch and assert the correct UTC-anchored
result (confirmed they fail against the old date-fns-based
implementation and pass against the fix).

Fixes TemaDeveloper#23
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Artemii's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Dashboard calendar date keys can mismatch server (UTC) vs client (local) timezone

1 participant