@zedtech/zedkit-ui
Format a compact duration
Turn a millisecond span or two instants into compact `6m 17s` / `1h 02m` text. Digits follow the locale argument; unit letters stay Latin. Install with npm.
At a glance
- Who: Developers showing elapsed time next to live status or logs.
- What: Turn a millisecond span or two instants into compact
6m 17s/1h 02mtext. Digits follow the locale argument; unit letters stay Latin. - Use when: For dense elapsed-time labels beside a live indicator or timestamp.
- Avoid when: For relative "3 minutes ago" — use
UpdatedAgo. For absolute times — render a<time dateTime>. - See also: Stamp data with its age
Install
pnpm add @zedtech/zedkit-uiLatest: 2.0.1 (via changesets).
Example
import { formatDuration } from "@zedtech/zedkit-ui";
formatDuration(377_000); // "6m 17s"
formatDuration(3_720_000); // "1h 02m"
formatDuration({ start: 0, end: 377_000 }, "fr"); // "6m 17s"Wraps: (none)
Accessibility
Returns a plain string. Digits follow the locale; h/m/s stay Latin. The caller owns the host — this is not a live region; place it next to a live indicator, not inside one.