Design System

Formats

How money, dates and times are displayed — ISO 4217 and ISO 8601 in the data, one human-readable form on screen. Format with the shared helpers, never by hand.

The platform spans markets that write money and dates differently, so consistency here is a brand concern exactly like colour: a dashboard where one widget says RM1,240 and another says MYR 1,240.00 reads as broken. The contract is standards in the data, one display form on screen — and the display form always comes from the shared helpers in @healthmetrics/ui, never from hand-rolled strings or ad-hoc Intl calls.

Currency

Amounts travel with an ISO 4217 code (MYR, SGD, JPY) and display code-first: MYR 1,240.00. The code, not a symbol — $ and RM are ambiguous the moment a corporate portal shows cross-border claims side by side. formatCurrency applies the currency's ISO minor units (JPY 1,000, not JPY 1,000.00) and the digit-grouping convention of its largest market, and its output is locale-independent, so statically exported pages hydrate cleanly.

Columns already labelled with the currency can drop the code (code: false); whole-unit summaries can drop the decimals (fractionDigits: 0). Amounts in running prose keep both.

Dates and times

Data carries ISO 8601 (2026-08-11, 2026-08-11T09:30:00+08:00); people never see it. On screen there is exactly one date form — 11 Aug 2026 — day first, three-letter month, full year. It is unambiguous across the DD/MM and MM/DD markets the platform serves, which no all-numeric form is. Times are 12-hour with a lowercase marker and no leading zero: 9:30 am. Together: 11 Aug 2026, 9:30 am.

A calendar date (policy start, date of birth) is a plain date — format it with formatDate and it will never shift a day across timezones. An instant (claim submitted, letter issued) belongs to a moment: render it in the viewer's timezone, or pass an explicit IANA timeZone when the viewer's zone is known server-side.

Relative time

Feeds and audit trails read better as distance than as coordinates: 2 hours ago, or the compact 2h in tight widgets like the Activity feed. formatRelative produces both, and beyond a week it falls back to the display date — "34 days ago" makes the reader do arithmetic that 8 Jul 2026 does for free. It requires the reference instant (now) explicitly: compute it once per response and pass it through, so a statically rendered page and its hydration pass cannot disagree.

The helpers, live

Every sample below is rendered by the real functions at build time — this table cannot drift from the code.

Currency — formatCurrency

formatCurrency(1240)MYR 1,240.00
formatCurrency(340.5, { currency: "SGD" })SGD 340.50
formatCurrency(1000, { currency: "JPY" })JPY 1,000
formatCurrency(480, { fractionDigits: 0 })MYR 480
formatCurrency(985, { code: false })985.00

Dates and times — formatDate / formatTime / formatDateTime

formatDate("2026-08-11")11 Aug 2026
formatDateTime(t, { timeZone: "Asia/Kuala_Lumpur" })11 Aug 2026, 5:30 pm
formatTime(t, { timeZone: "Asia/Kuala_Lumpur" })5:30 pm

Relative time — formatRelative

formatRelative(t, { now })2 hours ago
formatRelative(t, { now, style: "short" })2h
formatRelative(t, { now }) // 3 days aheadin 3 days
formatRelative(t, { now }) // beyond a week8 Jul 2026

Best practices

Do

  • Store and transmit ISO 4217 codes and ISO 8601 strings; format only at the edge, for display.
  • Use formatCurrency, formatDate, formatDateTime, formatRelative — one implementation, one look.
  • Put amounts in tabular-nums columns so figures align digit-for-digit.
  • Give <time> elements a machine-readable dateTime (ISO 8601, e.g. via toISODate).

Don't

  • Show raw ISO 8601 (2026-08-11T09:30:00Z) or all-numeric dates (11/08/2026) to people.
  • Use currency symbols (RM, $) in product UI — codes only.
  • Hand-roll formats with toLocaleString or ad-hoc Intl calls — ICU differences between build machine and browser cause hydration mismatches.
  • Default now to the clock when rendering relative time on the server — pass one instant through the whole response.

For engineers

import { formatCurrency, formatDate, formatRelative } from "@healthmetrics/ui";

formatCurrency(1240);                              // "MYR 1,240.00"
formatCurrency(340.5, { currency: "SGD" });        // "SGD 340.50"
formatDate("2026-08-11");                          // "11 Aug 2026"
formatRelative(submittedAt, { now, style: "short" }); // "2h" — now computed once per response

Which currencies are supported, exchange-rate handling and API serialisation are platform decisions, not design-system ones — these helpers assume valid ISO codes arrive and only say how they are shown.

On this page