feat(frontend): render dates via user preferences (IFC-2721)

Closed
PA
4mo ago
+617-92

Depends on #9776 (base branch ple-user-preferences-ui).

What & why (IFC-2721)

Renders user-facing dates/times against the user's date_format + timezone preferences, app-wide, through one mechanism — replacing scattered ad-hoc format(...)/toLocaleString(...) calls so date rendering is consistent and preference-driven.

Foundation

  • useFormatDate() (shared/context/date-preferences-context.tsx) — the single entry point: formatDate(date, variant?) with datetime (default) / date / relative variants.
  • DatePreferencesContext lives in shared (no dependency on entities/); DatePreferencesProvider (entities/preferences) fills it from useEffectivePreferences() and is mounted in app.tsx. No provider / source: "default" → browser locale + zone fallback (never a hardcoded pattern).
  • DateDisplay — historic look preserved (relative "x ago" for recent, compact otherwise); tooltip now shows the preferred full datetime + timezone; new variant="datetime" for inline full timestamps; dateFormat explicit escape hatch retained.
  • Timezone via first-party @date-fns/tz (TZDate); patternForKey exported from date-format-presets.ts.

Migration

Every user-facing raw date render routed through DateDisplay/useFormatDate at its original granularity — global-event, time-selector, search-nodes, duration-display, active-filter-tags, meta-details-tooltips, node-metadata-popover, refresh-button, relationship-properties, account-token-item, diff-empty.

Kept as-is (machine/serialized or intentionally browser-default): form inputs / date-pickers, toISOString() API/keys, chart ticks, tests, getDateDisplay, and the "browser default" hint in the preferences card.

Docs

  • Spec dev/specs/2026-04-user-preferences.md — DateDisplay section updated to the implemented design.
  • New dev/knowledge/frontend/date-rendering.md — the one mechanism, layering, variants, and what not to route through it.

Tests / gate

  • 21 new foundation tests (pure date.ts formatter across timezones, the hook/variants, DateDisplay) — establishes the date-rendering test pattern (fake timers + fixed instant).
  • Local: biome clean; tsc adds no new errors (pre-existing search-nodes/branches/diff errors are unrelated); Playwright suites green (90 tests across foundation + migrated + preferences areas).

🤖 Generated with Claude Code


Summary by cubic

Render all user-facing dates and times against the user’s date_format and timezone via one mechanism for consistent display. DateTime data attributes now show the full preferred datetime inline; activity/metadata timestamps keep the relative/compact style, with browser locale/zone fallback when no preference is set (IFC-2721).

  • New Features

    • App-wide date rendering via useFormatDate() and <DateDisplay>, powered by DatePreferencesContext; resolves semantic date_format via patternForKey and applies the user’s timezone. Supports datetime (default), date (derived from the full pattern), and relative.
    • DatePreferencesProvider (mounted in app.tsx) fills the context from useEffectivePreferences(); when source: "default" or no provider is mounted, it falls back to browser locale and zone.
    • <DateDisplay> keeps the relative/compact default; tooltip shows the preferred full datetime + timezone; adds variant="datetime" for inline full timestamps; dateFormat escape hatch retained.
    • New pure formatDate({ pattern, timezone }) using @date-fns/tz; docs added; tests cover the formatter, hook, and component.
  • Migration

    • Routed ad-hoc renders through DateDisplay/useFormatDate in events, time selector, search, duration tooltip, active filter tags, metadata tooltips, node metadata popover, refresh button, relationships, tokens, diff empty.
    • For DateTime data attributes (object details, table cells), use <DateDisplay variant="datetime"> to render the full preferred format inline.
    • Left as-is: form inputs/date‑pickers, toISOString() usage, chart ticks, and tests.