Files
paperclip/ui/src/lib/timeAgo.ts
Forgotten fad1bd27ce Add shared UI primitives, contexts, and reusable components
Add shadcn components: avatar, breadcrumb, checkbox, collapsible,
command, dialog, dropdown-menu, label, popover, scroll-area, sheet,
skeleton, tabs, textarea, tooltip. Add shared components: BreadcrumbBar,
CommandPalette, CompanySwitcher, CommentThread, EmptyState, EntityRow,
FilterBar, InlineEditor, MetricCard, PageSkeleton, PriorityIcon,
PropertiesPanel, StatusIcon, SidebarNavItem/Section. Add contexts for
breadcrumbs, dialogs, and side panels. Add keyboard shortcut hook and
utility helpers. Update layout, sidebar, and main app shell.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:57:00 -06:00

32 lines
777 B
TypeScript

const MINUTE = 60;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const WEEK = 7 * DAY;
const MONTH = 30 * DAY;
export function timeAgo(date: Date | string): string {
const now = Date.now();
const then = new Date(date).getTime();
const seconds = Math.round((now - then) / 1000);
if (seconds < MINUTE) return "just now";
if (seconds < HOUR) {
const m = Math.floor(seconds / MINUTE);
return `${m}m ago`;
}
if (seconds < DAY) {
const h = Math.floor(seconds / HOUR);
return `${h}h ago`;
}
if (seconds < WEEK) {
const d = Math.floor(seconds / DAY);
return `${d}d ago`;
}
if (seconds < MONTH) {
const w = Math.floor(seconds / WEEK);
return `${w}w ago`;
}
const mo = Math.floor(seconds / MONTH);
return `${mo}mo ago`;
}