MCPcopy Index your code
hub / github.com/Dimillian/CodexMonitor / formatRelativeTimeShort

Function formatRelativeTimeShort

src/utils/time.ts:36–58  ·  view source on GitHub ↗
(timestamp: number)

Source from the content-addressed store, hash-verified

34}
35
36export function formatRelativeTimeShort(timestamp: number) {
37 const now = Date.now();
38 const absSeconds = Math.abs(Math.round((timestamp - now) / 1000));
39 if (absSeconds < 60) {
40 return "now";
41 }
42 if (absSeconds < 60 * 60) {
43 return `${Math.max(1, Math.round(absSeconds / 60))}m`;
44 }
45 if (absSeconds < 60 * 60 * 24) {
46 return `${Math.max(1, Math.round(absSeconds / (60 * 60)))}h`;
47 }
48 if (absSeconds < 60 * 60 * 24 * 7) {
49 return `${Math.max(1, Math.round(absSeconds / (60 * 60 * 24)))}d`;
50 }
51 if (absSeconds < 60 * 60 * 24 * 30) {
52 return `${Math.max(1, Math.round(absSeconds / (60 * 60 * 24 * 7)))}w`;
53 }
54 if (absSeconds < 60 * 60 * 24 * 365) {
55 return `${Math.max(1, Math.round(absSeconds / (60 * 60 * 24 * 30)))}mo`;
56 }
57 return `${Math.max(1, Math.round(absSeconds / (60 * 60 * 24 * 365)))}y`;
58}

Callers 1

Sidebar.tsxFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected