feat(ui/agents): add _dayjs helper with relativeTime plugin

Centralizes dayjs.extend(relativeTime) so fromNow() is typed and
loaded across the agents components. relativeOrAbsolute() falls back
to '—' for null/invalid timestamps so callers don't have to
re-implement the guard.
This commit is contained in:
Ishaan Jaffer 2026-05-06 15:12:06 -07:00
parent be5ac1885a
commit d75651912e
No known key found for this signature in database

View file

@ -0,0 +1,20 @@
/**
* Shared dayjs helper for the cloud-agents dashboard.
*
* Loads the `relativeTime` plugin once so `dayjs(...).fromNow()` is
* typed and works across all the agents components. Without this, the
* plugin call is untyped and TS rejects it.
*/
import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";
dayjs.extend(relativeTime);
export function relativeOrAbsolute(value: string | null | undefined): string {
if (!value) return "—";
const d = dayjs(value);
if (!d.isValid()) return "—";
return d.fromNow();
}
export { dayjs };