Skip to content

Render analytics graph timestamps in the viewer's local timezone - #218

Merged
calebyhan merged 1 commit into
mainfrom
215/local-timezone-analytics
Aug 26, 2026
Merged

Render analytics graph timestamps in the viewer's local timezone#218
calebyhan merged 1 commit into
mainfrom
215/local-timezone-analytics

Conversation

@calebyhan

Copy link
Copy Markdown
Contributor

The analytics dashboard graph was displaying pageview timestamps that were
neither correctly UTC nor correctly local — timestamps returned by the API
were naive UTC datetimes with no offset, so the browser parsed them as
local time, and the chart then re-formatted that (already-shifted) value
with timeZone: "UTC", compounding the error. Depending on the viewer's
timezone, the labeled times could be off by hours in either direction.

Changes:

  • Added a validator on DailyPageViewCountDTO.day (backend/app/schemas/analytics.py)
    to attach UTC tzinfo to the naive datetime before serialization, so the
    API response carries a proper Z offset the client can parse unambiguously
  • Removed the forced timeZone: "UTC" in formatBucketLabel
    (frontend/src/components/admin/AnalyticsCharts.tsx) so the chart now
    renders timestamps in the viewer's local timezone by default
  • Dropped the now-inaccurate "(times in UTC)" label from the chart header
  • Updated a stale comment in the admin analytics router explaining the
    UTC-tagging behavior

Closes #215

Bucket timestamps were stored as naive UTC datetimes and serialized
without an offset, so the browser parsed them as local time while the
chart then re-formatted them with timeZone: "UTC" — showing neither
true UTC nor local time. Tag the timestamp as UTC in the DTO and drop
the forced UTC formatting so the chart renders in local time.

Closes #215
@github-actions

Copy link
Copy Markdown

Test Results

596 tests  ±0   596 ✅ ±0   53s ⏱️ ±0s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 6123d57. ± Comparison against base commit 2c3e2a2.

@MasonMines2006 MasonMines2006 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@calebyhan
calebyhan merged commit f2ef171 into main Aug 26, 2026
3 checks passed
@calebyhan
calebyhan deleted the 215/local-timezone-analytics branch August 26, 2026 19:56
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.

Analytics Graph is in UTC

2 participants