Files
archie/ui/src/lib/format.ts
T
sam d4e563a19c feat(ui): schedules table, runs page and Schedule trigger
Schedules list as a table with enable, run now, edit, duplicate, delete and
view runs; built-ins only enable, retime and run. The runs page links each
run's tasks through its capture's dispatches. The Start node gains a Schedule
trigger that picks or creates a schedule and binds the schedule source to the
workflow. Times show in a per-browser display zone set under Appearance; the
cron time zone and run retention are edited on the Schedules page.
2026-10-26 00:57:52 +11:00

41 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Display formatting shared across the dashboard pages. Pure functions: no
* DOM, no framework.
*/
/** Humanised relative time: "2 min ago". Raw timestamps make people do maths. */
export function ago(value: string | number | Date | null | undefined): string {
if (!value) return "–";
const then = value instanceof Date ? value : new Date(value);
const secs = Math.floor((Date.now() - then.getTime()) / 1000);
if (!Number.isFinite(secs)) return "–";
if (secs < 45) return "just now";
const units: Array<[string, number]> = [
["min", 60],
["hr", 3600],
["day", 86400],
["wk", 604800],
];
let label = "min";
let size = 60;
for (const [l, s] of units) {
if (secs >= s) [label, size] = [l, s];
}
const n = Math.floor(secs / size);
return `${n} ${label}${n === 1 ? "" : "s"} ago`;
}
/** Compact number: 2_400_000 -> "2.4M". Long digit strings do not scan. */
export function compact(n: number | null | undefined): string {
if (n == null || Number.isNaN(n)) return "–";
return new Intl.NumberFormat(undefined, {
notation: "compact",
maximumFractionDigits: 1,
}).format(n);
}
/** An exact date and time in zone, or in the browser's zone when zone is empty. */
export function exactTime(value: Date, zone: string): string {
return value.toLocaleString(undefined, zone ? { timeZone: zone, timeZoneName: "short" } : undefined);
}