UNPKG

@clickup/pg-microsharding

Version:
21 lines (19 loc) 444 B
/** * Builds a human-readable string from a number of seconds. Examples: * - "12s" * - "2m5s" * - "1h2m5s" */ export function secToHuman(sec: number | null): string { if (sec === null) { return "null"; } sec = Math.round(Math.max(sec, 0)); return [ sec >= 3600 && `${Math.floor(sec / 3600)}h`, sec >= 60 && `${Math.floor((sec % 3600) / 60)}m`, sec >= 0 && `${sec % 60}s`, ] .filter(Boolean) .join(""); }