Skip to content

Start day presets at the site's midnight, not the browser's - #9

Merged
sinnercode228 merged 1 commit into
mainfrom
fix/preset-site-day
Oct 28, 2026
Merged

sinnercode228 merged 1 commit into
mainfrom
fix/preset-site-day

Conversation

@sinnercode228

Copy link
Copy Markdown
Owner

The day presets ("Today", "Last 7 days", "Last 30 days") started at the browser's local midnight (startOfLocalDay() in web/src/lib/ranges.ts), but the server snaps ranges onto buckets in the site's time zone. When the two zones differ the window starts hours off: a UTC site viewed from Asia/Kolkata got six hours of the previous day under "Today".

Fix: the dashboard store now keeps the selected site's timeZone (set in App when the site list loads or the site changes). presetRange() takes it and computes the day start with startOfDay() from @pulse/core, the same function the server's day buckets use. Until the site list has loaded it falls back to the browser zone as before. AnalyticsPage adds the zone to its query key so the data refetches once the zone is known.

Testing: new case in web/test/lib.test.ts for UTC, Asia/Kolkata and America/New_York; it failed before the change (today for Asia/Kolkata returned the browser's midnight, 2026-06-10T00:00Z instead of 2026-06-09T18:30Z). Lint, format check, typecheck, the full test suite (also with TZ=Asia/Kolkata) and the build all pass locally.

Fixes #8

"Today", "Last 7 days" and "Last 30 days" took their start from
setHours(0, 0, 0, 0) in the browser's zone, while the server buckets in
the site's zone. With the two zones apart the window began hours off,
e.g. a UTC site viewed from Asia/Kolkata showed six hours of yesterday
under "Today".

The dashboard now keeps the selected site's time zone in its state and
presetRange() uses startOfDay() from @pulse/core with it, falling back
to the browser zone until the site list has loaded.

Fixes #8
@sinnercode228
sinnercode228 merged commit c7026ae into main Oct 28, 2026
2 checks passed
@sinnercode228
sinnercode228 deleted the fix/preset-site-day branch October 28, 2026 04:20
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.

Dashboard 'Today' starts at the browser's midnight, not the site's

1 participant