Active Foundation · Example
Relative time
Relative timeClient
| Value | mode | text |
|---|---|---|
| 2026-03-09T11:58:00Z | relative | 2 minutes ago |
| 2026-03-08T09:00:00Z | relative | 1 day ago |
| 2026-03-12T12:00:00Z | relative | in 3 days |
| 2026-02-01T08:00:00Z | absolute | 1 Feb 2026, 08:00 |
| 2026-03-09 | unavailable | (none) |
Full source examples/format/recency.tsx
// apps/docs/examples/format/recency.tsx'use client';
import {resolveRecency} from '@workspace/active-format';import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow,} from '@workspace/active-ui/components/primitives/table';
// A fixed "now": the example reads no clock, so every reader sees the same.const NOW = new Date('2026-03-09T12:00:00Z');const VALUES = [ '2026-03-09T11:58:00Z', '2026-03-08T09:00:00Z', '2026-03-12T12:00:00Z', '2026-02-01T08:00:00Z', '2026-03-09',];
/** * Relative within the threshold (seven days by default), absolute beyond it, * unavailable for a value that is not an instant. */export default function Recency() { return ( <Table> <TableHeader> <TableRow> <TableHead>Value</TableHead> <TableHead>mode</TableHead> <TableHead>text</TableHead> </TableRow> </TableHeader> <TableBody> {VALUES.map((value) => { const result = resolveRecency(value, 'en', {now: NOW}); return ( <TableRow key={value}> <TableCell className="font-mono text-xs">{value}</TableCell> <TableCell className="font-mono text-xs">{result.mode}</TableCell> <TableCell suppressHydrationWarning> {result.text || '(none)'} </TableCell> </TableRow> ); })} </TableBody> </Table> );}