API reference › @evolu/common › Time › formatMillisAsDuration
function formatMillisAsDuration(
millis: number &
Brand<"NonNaN"> &
Brand<"Finite"> &
Brand<"Int"> &
Brand<"NonNegative"> &
Brand<"LessThan281474976710655"> &
Brand<"Millis">,
): string;
Defined in: packages/common/src/Time.ts:631
Formats Millis as a human-readable duration string.
- Under 1 minute:
1.234s - Under 1 hour:
1m30.000s - Under 1 day:
1h30m45.000s - Under 1 week:
1d2h30m45.000s - Under 1 year:
1w2d3h30m45.000s - 1 year or more:
1y2w3d4h30m45.000s
Weeks are 7 days and years are 365 days.
Example
import { assertEqual, formatMillisAsDuration, Millis } from "@evolu/common";
assertEqual(formatMillisAsDuration(Millis.orThrow(1234)), "1.234s");
assertEqual(formatMillisAsDuration(Millis.orThrow(90000)), "1m30.000s");
assertEqual(formatMillisAsDuration(Millis.orThrow(90061000)), "1d1h1m1.000s");