// The relative-time wording both UIs share: one unit, clamped at zero, and the // forward form. Run by `npm test`. import assert from "node:assert/strict"; import { test } from "node:test"; import { fmtAgo, fmtUntil } from "../../shared/src/time.ts"; test("an age reads in its largest whole unit", () => { assert.equal(fmtAgo(5), "5s ago"); assert.equal(fmtAgo(59), "59s ago"); assert.equal(fmtAgo(60), "1m ago"); assert.equal(fmtAgo(3599), "59m ago"); assert.equal(fmtAgo(3600), "1h ago"); assert.equal(fmtAgo(86399), "23h ago"); assert.equal(fmtAgo(86400), "1d ago"); assert.equal(fmtAgo(3 * 86400 + 5), "3d ago"); }); test("a clock a little ahead never reads as a negative age", () => { assert.equal(fmtAgo(-3), "0s ago"); }); test("a fractional age is floored", () => { assert.equal(fmtAgo(61.9), "1m ago"); }); test("an instant ahead reads in the same units, forward", () => { assert.equal(fmtUntil(5), "in 5s"); assert.equal(fmtUntil(300), "in 5m"); assert.equal(fmtUntil(7200), "in 2h"); assert.equal(fmtUntil(2 * 86400), "in 2d"); assert.equal(fmtUntil(-4), "in 0s"); });