MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / formatRelativeTime

Function formatRelativeTime

apps/vis/web/src/util/time.ts:2–17  ·  view source on GitHub ↗
(epochMs: number)

Source from the content-addressed store, hash-verified

1/** Format an epoch-ms timestamp as a short relative string ("2m ago", "3h ago"). */
2export function formatRelativeTime(epochMs: number): string {
3 if (!epochMs || !Number.isFinite(epochMs)) return '—';
4 const diff = Date.now() - epochMs;
5 if (diff < 0) return 'just now';
6 const s = Math.floor(diff / 1000);
7 if (s < 60) return `${s}s ago`;
8 const m = Math.floor(s / 60);
9 if (m < 60) return `${m}m ago`;
10 const h = Math.floor(m / 60);
11 if (h < 24) return `${h}h ago`;
12 const d = Math.floor(h / 24);
13 if (d < 30) return `${d}d ago`;
14 const mo = Math.floor(d / 30);
15 if (mo < 12) return `${mo}mo ago`;
16 return `${Math.floor(mo / 12)}y ago`;
17}
18
19/** Format an epoch-ms timestamp as ISO-ish local time (YYYY-MM-DD HH:MM:SS). */
20export function formatAbsoluteTime(epochMs: number): string {

Callers 6

SessionCardFunction · 0.90
ManifestCardFunction · 0.90
TsValueFunction · 0.90
TaskCardFunction · 0.90
CronCardFunction · 0.90
SessionDetailPageFunction · 0.90

Calls 1

nowMethod · 0.65

Tested by

no test coverage detected