1export const getRelativeTime = (date: Date, now: Date = new Date()) => {
2 const diff = now.getTime() - date.getTime();
3 const seconds = Math.floor(diff / 1000);
4 const minutes = Math.floor(seconds / 60);
5 const hours = Math.floor(minutes / 60);
6 const days = Math.floor(hours / 24);
7 const months = Math.floor(days / 30);
8 const years = Math.floor(months / 12);
9
10 if (years > 0) return `${years}y`;
11 if (months > 0) return `${months}mo`;
12 if (days > 0) return `${days}d`;
13 if (hours > 0) return `${hours}h`;
14 if (minutes > 0) return `${minutes}m`;
15 if (seconds > 0) return `${seconds}s`;
16 return 'now';
17};