Skip to content
Components / Metrics

Relative time

"3 minutes ago" in any locale, with the full date on hover.

@fabrials/ui
Loading state

Updated , published , in Spanish .

Deterministic, in a fixed zone:

Installation

  1. Import the control from @fabrials/ui, after setting the app up.

    TypeScript
    import { RelativeTime, formatRelativeTime, formatAbsoluteTime } from "@fabrials/ui";

API reference

Prop / exportTypeDescription
dateDate | string | numberThe moment.
localestringLanguage of the phrase.
absoluteFormatIntl.DateTimeFormatOptions | (date, now) => optionsDeterministic mode: print an absolute date, no timer. A function picks the options per date (drop the year when it is this year).
nownumber | () => numberThe clock. A number is a fixed instant and stops the timer; a function is read at every tick (a server-anchored clock).
timeZonestringThe zone dates and the title are printed in. Required when a deterministic time (absoluteFormat or a fixed now) is server-rendered; otherwise the server and the browser print different text.

Behavior

Refreshes while the page is visible; renders a <time> element with the exact date. With absoluteFormat or a fixed now it is deterministic; with a timeZone it hydrates without a mismatch and without suppressing the warning.

Accessibility

Keyboard and contrast
Keep visible labels, keyboard focus and status announcements when customizing. These components inherit your theme; maintain sufficient contrast in both color modes. The preview is keyboard operable.