pretty-ms duration formatting: working versions (tested 2026-10-16)
Format millisecond durations with pretty-ms using compact, verbose and colon notation styles plus millisecond/second precision options, covering zero, sub-second, multi-hour and negative values offline.
passed5 passed · 0 failed2026-10-16 02:18 UTC- Status
- passed
- Last passed
- 2026-10-16 02:18 UTC
- Tests
- 5 / 5
- Language
- TypeScript
- Runtime
- node v22.23.3
pinned versions3
pretty-ms@10.0.0@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false npm test
test environment
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38839686104
The code
Exactly the files that passed. Your agent can pull them with get_recipe("pretty-ms-format") (install), or see them on GitHub.
package.json
{
"name": "pretty-ms-format",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"pretty-ms": "10.0.0"
},
"devDependencies": {
"@types/node": "26.6.5",
"tsx": "4.23.15"
}
}
src/format.ts
import prettyMilliseconds from "pretty-ms";
export type DurationStyle = "default" | "compact" | "verbose" | "clock";
export function formatDuration(
milliseconds: number,
style: DurationStyle = "default",
): string {
switch (style) {
case "compact":
return prettyMilliseconds(milliseconds, { compact: true });
case "verbose":
return prettyMilliseconds(milliseconds, { verbose: true });
case "clock":
return prettyMilliseconds(milliseconds, { colonNotation: true });
default:
return prettyMilliseconds(milliseconds);
}
}
export function formatPrecise(milliseconds: number): string {
return prettyMilliseconds(milliseconds, {
separateMilliseconds: true,
secondsDecimalDigits: 0,
millisecondsDecimalDigits: 2,
});
}
test/format.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import prettyMilliseconds from "pretty-ms";
import { formatDuration, formatPrecise } from "../src/format.ts";
test("formats zero, sub-second and negative durations", () => {
assert.equal(formatDuration(0), "0ms");
assert.equal(formatDuration(500), "500ms");
assert.equal(formatDuration(1500), "1.5s");
assert.equal(formatDuration(-1500), "-1.5s");
});
test("formats multi-hour durations", () => {
assert.equal(formatDuration(3600000), "1h");
assert.equal(formatDuration(1337000000), "15d 11h 23m 20s");
});
test("supports compact and verbose styles", () => {
assert.equal(formatDuration(1337000000, "compact"), "15d");
assert.equal(
formatDuration(1337000000, "verbose"),
"15 days 11 hours 23 minutes 20 seconds",
);
});
test("supports colon notation", () => {
assert.equal(formatDuration(1000, "clock"), "0:01");
assert.equal(formatDuration(60000, "clock"), "1:00");
assert.equal(formatDuration(3600000, "clock"), "1:00:00");
});
test("supports separate milliseconds and precision options", () => {
assert.equal(
prettyMilliseconds(1234, { separateMilliseconds: true }),
"1s 234ms",
);
assert.equal(prettyMilliseconds(1234, { secondsDecimalDigits: 0 }), "1s");
assert.match(formatPrecise(1234), /^1s 234(\.0+)?ms$/);
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
~/.cursor/mcp.json
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }.vscode/mcp.json
{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }MCP settings
{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.