Runes
relativeTime
“3 minutes ago”, in English, Arabic, Turkish and Sorani Kurdish — and kept true.
A timestamp rendered once is wrong a minute later. A timestamp rendered by a timer per row is a page that shimmers. This is one shared timer per cadence, and four languages written out properly.
Relative time
Four languages, one shared timer — and it ticks while you watch.
just now
since this example opened — watch it tick
now
just now
2 minutes ago
2 minutes ago
3 hours ago
3 hours ago
in 5 days
in 5 days
2 years ago
2 years ago
<script lang="ts"> import { relativeTime, SegmentedButton, Text, Divider } from 'omaris'; import type { RelativeStyle } from 'omaris'; const locales = [ { tag: 'en', label: 'English' }, { tag: 'ar', label: 'العربية' }, { tag: 'tr', label: 'Türkçe' }, { tag: 'ckb', label: 'کوردی' } ]; let locale = $state('en'); let style = $state<RelativeStyle>('long'); const moments = [ { name: 'now', at: () => new Date() }, { name: '2 minutes ago', at: () => new Date(Date.now() - 2 * 60_000) }, { name: '3 hours ago', at: () => new Date(Date.now() - 3 * 3_600_000) }, { name: 'in 5 days', at: () => new Date(Date.now() + 5 * 86_400_000) }, { name: '2 years ago', at: () => new Date(Date.now() - 2 * 365 * 86_400_000) } ].map((moment) => ({ ...moment, time: relativeTime(moment.at, { locale: () => locale, style: () => style }) })); const started = new Date(); const live = relativeTime(() => started, { locale: () => locale, style: () => style });</script><div class="flex w-full flex-col gap-4"> <div class="flex flex-wrap gap-3"> <SegmentedButton bind:value={locale} items={locales.map((l) => ({ value: l.tag, label: l.label }))} /> <SegmentedButton bind:value={style} items={[ { value: 'long', label: 'Long' }, { value: 'short', label: 'Short' } ]} /> </div> <div class="rounded-xl border border-border p-4" dir={live.dir}> <Text variant="title-md">{live.text}</Text> <Text variant="body-sm" tone="muted">since this example opened — watch it tick</Text> </div> <Divider /> <div class="flex flex-col gap-2"> {#each moments as moment (moment.name)} <div class="flex items-baseline justify-between gap-4"> <Text variant="body-sm" tone="muted">{moment.name}</Text> <Text variant="body-md" dir={moment.time.dir}>{moment.time.text}</Text> </div> {/each} </div></div> Use it
<script> import { relativeTime } from 'omaris'; let { post } = $props(); const posted = relativeTime(() => post.createdAt);</script><time datetime={posted.iso} title={posted.absolute}>{posted.text}</time> It re-renders itself as the clock moves — every second under a minute, every half minute under an hour, and progressively less often after that.
Four languages
en, ar, tr and ckb, taken from <html lang> unless you say otherwise:
relativeTime(() => date, { locale: 'ckb' });relativeTime(() => date, { locale: () => user.locale, style: 'short' }); | long | short | |
|---|---|---|
| English | 3 minutes ago | 3m ago |
| العربية | قبل 3 دقائق | قبل 3 د |
| Türkçe | 3 dakika önce | 3 dk önce |
| کوردی | 3 خولەک لەمەوپێش | 3 خ لەمەوپێش |
They are written out rather than delegated to Intl.RelativeTimeFormat, for two reasons. Sorani Kurdish is not in most ICU builds at all, and a set of four languages where one is formatted by a different mechanism than the other three is a set that drifts. Writing them out also means Arabic gets its counting right — the bare noun for one, the dual for two, the plural for three to ten, and back to the singular from eleven:
| 1 | قبل دقيقة |
| 2 | قبل دقيقتين |
| 3 | قبل 3 دقائق |
| 11 | قبل 11 دقيقة |
dir is 'rtl' for Arabic and Kurdish, for your own layout decisions.
Numerals stay Western in every language, for the same reason every other formatter in this library pins them — a table that switches digit systems with the language is unreadable to the people who asked for the language. Pass digits: 'auto' for ٣ دقائق. The clock in absolute is 12-hour with AM/PM either way — digits frees the numerals, never the clock.
Add a language, or replace one of the four:
import { registerRelativeLocale } from 'omaris';registerRelativeLocale('fa', { dir: 'rtl', now: { … }, unit: (…) => …, past: …, future: … }); Old timestamps
Past a certain age a count stops being information — “47 weeks ago” tells you nothing. maxAge switches to a real date:
relativeTime(() => date, { maxAge: 7 * 24 * 3600_000 }); // relative for a week, then a date What it exposes
posted.text; // '3 minutes ago'posted.value; // 3posted.unit; // 'minute'posted.past; // trueposted.isNow; // within the "just now" windowposted.expired; // maxAge has switched it to a dateposted.absolute; // 'September 6, 2026 at 2:03 PM'posted.iso; // for <time datetime>posted.dir; // 'rtl' for ar and ckb One-off
For a tooltip, a log line, a table cell that never updates — the same formatting, without the timer:
import { formatRelative } from 'omaris';formatRelative(comment.at); // '3 minutes ago'formatRelative(comment.at, { locale: 'ar' }); // 'قبل 3 دقائق'formatRelative(due, { locale: 'tr', style: 'short' }); // '2 g sonra'