Description
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 tonew Date(ms).toLocaleDateString()in the runtime default locale (:19), so the same list row reads differently on two phones. It is re-exported throughcomponents/chat/tool-views.tsx:28-33and 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" whereformatRelativeTimewould read "just now".observationAge(packages/ui-react/src/components/chat/state-room-notice.tsx:12-19) already usesIntl.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 singleDISPLAY_LOCALEconstant ("en-US"),formatRelativeTimeandformatDuration. formatRelativeTimeusesIntl.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 usestoLocaleDateString(DISPLAY_LOCALE, …).formatRefreshedbecomes"refreshed " + formatRelativeTime(...)for past values, with its ownnever refreshed.observationAgekeeps its long style, but takes the locale fromDISPLAY_LOCALE.formatDurationusesIntl.DurationFormat(DISPLAY_LOCALE, { style: "narrow" })when it is defined and the existing manual construction otherwise. It gains an hours unit from 60 minutes, as1h 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 asformatWhen. - Translating the UI, or following the device locale.
- Kit story copy such as
"2m ago"inAskUserCard.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"andformatRelativeTime(now - 3 * 60_000) === "3m ago".- A value 8 days old renders the same
en-USdate whateverprocess.env.LANGorIntl.DateTimeFormat().resolvedOptions().localeis.
- 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's3_599_500 → "60m 0s"expectation becomes"1h 0m";3_600_000also 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 deletingIntl.DurationFormatin 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 lintContract impact
- This touches the integration contract, so it needs the
contractlabel, aCONTRACT: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
schlessera commentedon Oct 22, 2026
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.