WIP! A BB-style forum, on the ATmosphere!
We're still working... we'll be back soon when we have something to show off!
node
typescript
hono
htmx
atproto
1/**
2 * Returns a human-readable relative time string for a given date.
3 * Examples: "just now", "5 minutes ago", "2 hours ago", "3 days ago", "2026-01-01"
4 */
5export function timeAgo(date: Date): string {
6 const diffMs = Date.now() - date.getTime();
7 const diffSecs = Math.floor(diffMs / 1000);
8
9 if (diffSecs < 60) return "just now";
10
11 const diffMins = Math.floor(diffSecs / 60);
12 if (diffMins < 60) return `${diffMins} minute${diffMins === 1 ? "" : "s"} ago`;
13
14 const diffHours = Math.floor(diffMins / 60);
15 if (diffHours < 24) return `${diffHours} hour${diffHours === 1 ? "" : "s"} ago`;
16
17 const diffDays = Math.floor(diffHours / 24);
18 if (diffDays < 30) return `${diffDays} day${diffDays === 1 ? "" : "s"} ago`;
19
20 return date.toISOString().split("T")[0];
21}