Intl.RelativeTimeFormat for proper i18n — zero hand-rolled formatting strings.
formatRelativeTime()
Pure utility function. AcceptsDate, ISO string, or epoch milliseconds:
Signature
Options
Thresholds
The function picks the most appropriate unit based on elapsed time:
Future dates work the same way: “in 5 minutes”, “in 2 hours”.
All output comes from
Intl.RelativeTimeFormat including the “now” case (format(0, 'second')).
This means every string is locale-aware — no English-only special cases.RelativeTime
Auto-updating component that renders a<time> element. The displayed text refreshes automatically using adaptive intervals.
Props
Rendered HTML
datetime attribute always contains the ISO string for machine readability. The title attribute defaults to the full formatted date via Intl.DateTimeFormat.
Adaptive Update Intervals
WhenupdateInterval is not set, the component picks a smart interval based on elapsed time:
Old timestamps stop updating entirely — zero timer overhead.
SSR Behavior
During SSR, the component renders the static formatted text. The update timer only starts on the client viaonMount(). There may be a minor text drift between SSR and client hydration if a threshold boundary is crossed (e.g., SSR renders “4 minutes ago”, client hydrates with “5 minutes ago”). This is acceptable — the datetime attribute is always correct, and the text updates on the next tick.