MCPcopy Index your code
hub / github.com/winfunc/opcode / formatUnixTimestamp

Function formatUnixTimestamp

src/lib/date-utils.ts:9–42  ·  view source on GitHub ↗
(timestamp: number)

Source from the content-addressed store, hash-verified

7 * formatUnixTimestamp(1735555200) // "Dec 30, 2024"
8 */
9export function formatUnixTimestamp(timestamp: number): string {
10 const date = new Date(timestamp * 1000);
11 const now = new Date();
12
13 // If it's today, show time
14 if (isToday(date)) {
15 return formatTime(date);
16 }
17
18 // If it's yesterday
19 if (isYesterday(date)) {
20 return `Yesterday, ${formatTime(date)}`;
21 }
22
23 // If it's within the last week, show day of week
24 if (isWithinWeek(date)) {
25 return `${getDayName(date)}, ${formatTime(date)}`;
26 }
27
28 // If it's this year, don't show year
29 if (date.getFullYear() === now.getFullYear()) {
30 return date.toLocaleDateString('en-US', {
31 month: 'short',
32 day: 'numeric'
33 });
34 }
35
36 // Otherwise show full date
37 return date.toLocaleDateString('en-US', {
38 month: 'short',
39 day: 'numeric',
40 year: 'numeric'
41 });
42}
43
44/**
45 * Formats an ISO timestamp string to a human-readable date

Callers 3

ClaudeMemoriesDropdownFunction · 0.90
formatISOTimestampFunction · 0.85

Calls 5

isTodayFunction · 0.85
isYesterdayFunction · 0.85
isWithinWeekFunction · 0.85
getDayNameFunction · 0.85
formatTimeFunction · 0.70

Tested by

no test coverage detected