MCPcopy Create free account
hub / github.com/codeaashu/claude-code / formatDate

Function formatDate

web/lib/utils.ts:8–26  ·  view source on GitHub ↗
(timestamp: number)

Source from the content-addressed store, hash-verified

6}
7
8export function formatDate(timestamp: number): string {
9 const date = new Date(timestamp);
10 const now = new Date();
11 const diffMs = now.getTime() - date.getTime();
12 const diffMins = Math.floor(diffMs / 60000);
13 const diffHours = Math.floor(diffMs / 3600000);
14 const diffDays = Math.floor(diffMs / 86400000);
15
16 if (diffMins < 1) return "just now";
17 if (diffMins < 60) return `${diffMins}m ago`;
18 if (diffHours < 24) return `${diffHours}h ago`;
19 if (diffDays < 7) return `${diffDays}d ago`;
20
21 return date.toLocaleDateString("en-US", {
22 month: "short",
23 day: "numeric",
24 year: date.getFullYear() !== now.getFullYear() ? "numeric" : undefined,
25 });
26}
27
28export function truncate(str: string, maxLength: number): string {
29 if (str.length <= maxLength) return str;

Callers 1

NotificationItemFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected