(date: Date | string)
| 32 | } |
| 33 | |
| 34 | export function fuzzyTimeAgo(date: Date | string): string { |
| 35 | const now = new Date(); |
| 36 | if (isToday(date)) return 'Today'; |
| 37 | if (isYesterday(date)) return 'Yesterday'; |
| 38 | |
| 39 | const days = differenceInCalendarDays(now, date); |
| 40 | if (days < 7) return `${days} day${days > 1 ? 's' : ''} ago`; |
| 41 | |
| 42 | const weeks = differenceInCalendarWeeks(now, date); |
| 43 | if (weeks < 4) return `${weeks} week${weeks > 1 ? 's' : ''} ago`; |
| 44 | |
| 45 | const months = differenceInCalendarMonths(now, date); |
| 46 | return `${months} month${months > 1 ? 's' : ''} ago`; |
| 47 | } |
| 48 | |
| 49 | export function timeAgo(date: Date | string): string { |
| 50 | return formatDistanceToNow(date, { addSuffix: true }); |
no outgoing calls
no test coverage detected
searching dependent graphs…