deckhearth/lib/format-relative-time.js
varutasu b9e840ff3a
Realign dashboard home nav and wire honest ownership stats (#164)
Flatten authenticated sidebar IA, move admin to the profile menu, right-align TopSearchBar actions, and replace placeholder dashboard panels with data from /api/user/stats and /api/user-cards.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-15 16:47:59 -05:00

26 lines
700 B
JavaScript

/**
* Human-readable relative time for activity feeds (e.g. "2m ago").
*/
export function formatRelativeTime(isoString) {
if (!isoString) return '';
const then = new Date(isoString).getTime();
if (Number.isNaN(then)) return '';
const diffMs = Date.now() - then;
if (diffMs < 0) return 'Just now';
const mins = Math.floor(diffMs / 60000);
if (mins < 1) return 'Just now';
if (mins < 60) return `${mins}m ago`;
const hours = Math.floor(mins / 60);
if (hours < 24) return `${hours}h ago`;
const days = Math.floor(hours / 24);
if (days < 7) return `${days}d ago`;
return new Date(isoString).toLocaleDateString(undefined, {
month: 'short',
day: 'numeric',
});
}