The 1st decentralized social network for sharing when you're on the toilet. Post a "flush" today! Powered by the AT Protocol.
at main 39 lines 842 B view raw
1export function formatRelativeTime(dateString: string): string { 2 if (!dateString) return ''; 3 4 const date = new Date(dateString); 5 const now = new Date(); 6 const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000); 7 8 // Less than a minute 9 if (diffInSeconds < 60) { 10 return 'just now'; 11 } 12 13 // Minutes 14 const minutes = Math.floor(diffInSeconds / 60); 15 if (minutes < 60) { 16 return `${minutes}m ago`; 17 } 18 19 // Hours 20 const hours = Math.floor(minutes / 60); 21 if (hours < 24) { 22 return `${hours}h ago`; 23 } 24 25 // Days 26 const days = Math.floor(hours / 24); 27 if (days < 7) { 28 return `${days}d ago`; 29 } 30 31 // Weeks 32 const weeks = Math.floor(days / 7); 33 if (weeks < 5) { 34 return `${weeks}w ago`; 35 } 36 37 // Fallback to formatted date for older posts 38 return date.toLocaleDateString(); 39}