Skip to content

Follow system timezone changes in message timeline formatters - #3276

Draft
sagestainsbys wants to merge 1 commit into
block:mainfrom
sagestainsbys:sages/system-timezone-default
Draft

Follow system timezone changes in message timeline formatters#3276
sagestainsbys wants to merge 1 commit into
block:mainfrom
sagestainsbys:sages/system-timezone-default

Conversation

@sagestainsbys

Copy link
Copy Markdown

Summary

While travelling between the US and Australia I noticed Buzz kept rendering message timestamps in US time after my Mac had switched back to Australia/Melbourne — only a full restart fixed it.

Cause: the message timeline's Intl.DateTimeFormat instances in desktop/src/features/messages/lib/dateFormatters.ts are constructed once at module load, and a formatter snapshots the timezone it was constructed in. A long-running app therefore keeps formatting in the stale zone after the OS timezone changes underneath it.

This change caches the formatters per resolved timezone instead: each call re-probes Intl.DateTimeFormat().resolvedOptions().timeZone (cheap), reuses the cached instances while the zone is stable, and rebuilds them when it changes — so a timezone change is picked up without a restart.

Scope notes:

  • Locale is intentionally left as en-US: the surrounding formatting logic is English-only (hard-coded ordinal suffixes, "Today"/"Yesterday", AM/PM stripping), so following the system locale is a bigger, separable change.
  • A few other spots cache en-US formatters at module level (features/home/ui/FeedSection.tsx, features/home/lib/inbox.ts, features/messages/ui/DraftsPanel.tsx, features/agents/ui/agentSessionUtils.ts, features/search/*, features/channels/lib/ephemeralChannel.ts) and have the same staleness; this PR fixes the message timeline, the most visible surface. Happy to follow up on the rest with the same pattern if maintainers agree.

Related issue

None found — searched issues and PRs for timezone-related reports.

Testing

  • New regression test: formats a fixed instant under TZ=America/Los_Angeles, switches to TZ=Australia/Melbourne mid-process, and asserts the rendered times move with the zone (fails against the previous module-level formatters).
  • pnpm test: 3722/3722 pass.
  • pnpm exec tsc --noEmit and pnpm check (biome + repo checks) clean.

The message timeline's Intl.DateTimeFormat instances were constructed
once at module load, and a formatter snapshots the timezone it was
constructed in. A long-running Buzz therefore kept rendering timestamps
in the previous zone after the OS timezone changed (e.g. travelling
between timezones), until a full restart.

Cache the formatters per resolved timezone instead: instances are
reused while the zone is stable and rebuilt when it changes.

Signed-off-by: Sage Stainsby <sages@squareup.com>
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.

1 participant