Skip to content

ui-react: one locale-pinned time formatter module on Intl.RelativeTimeFormat and Intl.DurationFormat #2606

Open

Description

@schlessera

Context

ui-react has three hand-built relative-time formatters, and each rounds and localises differently:

  • formatRelativeTime (packages/ui-react/src/lib/format-time.ts:2-20) builds "3m ago" / "in 3m" by hand. It floors past values and ceils future ones. Past a week it falls back to new Date(ms).toLocaleDateString() in the runtime default locale (:19), so the same list row reads differently on two phones. It is re-exported through components/chat/tool-views.tsx:28-33 and used by session, activity, queue and ask-user rows.
  • formatRefreshed (packages/ui-react/src/components/settings/models-list.tsx:279-287) is a second copy that rounds (Math.round). Thirty seconds after a refresh, it reads "refreshed 1m ago" where formatRelativeTime would read "just now".
  • observationAge (packages/ui-react/src/components/chat/state-room-notice.tsx:12-19) already uses Intl.RelativeTimeFormat("en-US"), with the long style ("3 minutes ago").

Durations come from formatDuration (packages/ui-react/src/lib/duration.ts:2-10). It has no hours unit, so 2 hours renders as 120m 0s.

Locale is pinned ad hoc: "en-US" appears literally in 7 ui-react/ui-kit files, and there is no shared constant.

Guide js/format-human-readable-durations: "DO use Intl.DurationFormat for localized string formatting and automatic pluralization, or fall back to manual construction if not supported." Feature-detect with typeof Intl.DurationFormat !== 'undefined'.

Support (MDN browser-compat-data):

  • Intl.DurationFormat: Chrome Android 129, Samsung 28, Firefox Android 136.
  • Intl.RelativeTimeFormat: all targets.

In Bun, new Intl.RelativeTimeFormat("en-US", { style: "narrow" }) gives "3m ago" and "in 3m". new Intl.DurationFormat("en-US", { style: "narrow" }) gives "2m 5s", but it drops zero units ("1m") unless the *Display: "always" options are set.

Blocked by #2605

Scope

  • One module in packages/ui-react/src/lib/ exports a single DISPLAY_LOCALE constant ("en-US"), formatRelativeTime and formatDuration.
  • formatRelativeTime uses Intl.RelativeTimeFormat(DISPLAY_LOCALE, { style: "narrow" }), with one rounding rule: floor for the past, ceil for the future. The "just now" and "in less than a minute" phrases stay. Past a week it uses toLocaleDateString(DISPLAY_LOCALE, …).
  • formatRefreshed becomes "refreshed " + formatRelativeTime(...) for past values, with its own never refreshed.
  • observationAge keeps its long style, but takes the locale from DISPLAY_LOCALE.
  • formatDuration uses Intl.DurationFormat(DISPLAY_LOCALE, { style: "narrow" }) when it is defined and the existing manual construction otherwise. It gains an hours unit from 60 minutes, as 1h 2m. Below one minute, both paths keep the current "12.3s" form, and current sub-hour test strings are kept. Apply ui-react: run durations read "1m 60s" and "60.0s" because rounded seconds never carry #2605's rounding/carry before selecting units. At one hour and above use hours and minutes with both displayed (1h 0m, 2h 1m); below one hour keep minutes and seconds including zero seconds (1m 0s). The same forms apply to the native and manual paths.

Out of scope

  • Other "en-US" call sites (scope-cap-card.tsx, track-display.ts, diagnostic-review.tsx, compose-stats.ts, asr-webspeech.ts, PlaceMap.tsx), and absolute timestamps such as formatWhen.
  • Translating the UI, or following the device locale.
  • Kit story copy such as "2m ago" in AskUserCard.tsx.

Acceptance criteria

  • git grep -n "m ago\|h ago`|d ago`" -- packages/ui-react/src` returns nothing: no hand-built unit suffixes remain.
  • With the clock frozen in a unit test:
    • formatRelativeTime(now - 30_000) === "just now" and formatRelativeTime(now - 3 * 60_000) === "3m ago".
    • A value 8 days old renders the same en-US date whatever process.env.LANG or Intl.DateTimeFormat().resolvedOptions().locale is.
  • A refresh 30 seconds ago reads "refreshed just now". That test fails before the change and passes after.
  • formatDuration(7_260_000) === "2h 1m". Preserve existing sub-hour strings and ui-react: run durations read "1m 60s" and "60.0s" because rounded seconds never carry #2605's carry correctness. At the intentional hours boundary, ui-react: run durations read "1m 60s" and "60.0s" because rounded seconds never carry #2605's 3_599_500 → "60m 0s" expectation becomes "1h 0m"; 3_600_000 also becomes "1h 0m". Document and update those boundary expectations rather than asserting that every ui-react: run durations read "1m 60s" and "60.0s" because rounded seconds never carry #2605 string is unchanged. The fallback path is tested by deleting Intl.DurationFormat in the test and restoring its full property descriptor in teardown, and it gives the same strings.
  • Android support: the PR names the feature check (typeof Intl.DurationFormat !== "undefined") and the manual fallback. No polyfill is added.

Verification

bun run test packages/ui-react/tests/tool-views.test.ts
bun run test packages/ui-react
bun run typecheck
bun run lint

Contract impact

  • This touches the integration contract, so it needs the contract label, a CONTRACT: commit prefix, and the doc updated in the same commit.
  • This changes a published package's behaviour, so it needs a changeset.

@schlessera/brain-ui-react: hours appear in durations, and "refreshed" rounding changes.

2026-10-22 triage at main aa8c8966b59f031f054f4876dbca84048b40ae4f: verified the three time paths and duration formatter. Resolved the acceptance-criteria contradiction with prerequisite #2605: hours intentionally change the rounded one-hour boundary to 1h 0m, while sub-hour strings and carry correctness remain. Classify as type: feat because the requested hours/locale/rounding output changes are observable. Add agent-ready alongside blocked; #2605 remains OPEN at p2, which satisfies this p3 issue's prerequisite priority. No implementation or successful runtime test is claimed.

Activity

  1. added
    type: refactor
    area: ui-react
    priority: p3
    blocked
    on Oct 22, 2026
  2. added
    type: feat
    agent-ready
    and removed
    type: refactor
    on Oct 22, 2026
  3. schlessera commented on Oct 22, 2026

    @schlessera
    OwnerAuthor

    2026-10-22 triage at main aa8c8966b59f031f054f4876dbca84048b40ae4f: verified the three time paths and duration formatter. Resolved the acceptance-criteria contradiction with prerequisite #2605: hours intentionally change the rounded one-hour boundary to 1h 0m, while sub-hour strings and carry correctness remain. Classify as type: feat because the requested hours/locale/rounding output changes are observable. Add agent-ready alongside blocked; #2605 remains OPEN at p2, which satisfies this p3 issue's prerequisite priority. No implementation or successful runtime test is claimed.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: ui-reactblockedpriority: p3type: feat

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions