MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / formatRelativeTime

Function formatRelativeTime

packages/react/src/lib/relative-time.ts:9–19  ·  view source on GitHub ↗
(timestamp: number, now = Date.now())

Source from the content-addressed store, hash-verified

7 * clock.
8 */
9export const formatRelativeTime = (timestamp: number, now = Date.now()): string => {
10 const diffMs = Math.max(0, now - timestamp);
11 const minutes = Math.floor(diffMs / 60_000);
12 if (minutes < 1) return "just now";
13 if (minutes < 60) return `${minutes}m ago`;
14 const hours = Math.floor(minutes / 60);
15 if (hours < 24) return `${hours}h ago`;
16 const days = Math.floor(hours / 24);
17 if (days < 7) return `${days}d ago`;
18 return new Date(timestamp).toLocaleDateString(undefined, { month: "short", day: "numeric" });
19};

Callers 3

ArtifactCardFunction · 0.90
ArtifactDetailPageFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected