import { format, differenceInMinutes, differenceInHours, differenceInDays } from 'date-fns' export function getRelativeTime (timestamp, now = new Date()) { try { const mins = differenceInMinutes(now, timestamp) const hours = differenceInHours(now, timestamp) const days = differenceInDays(now, timestamp) if (mins === 0) return 'Just now' if (mins < 60) return `${mins}m ago` if (hours < 24) return `${hours}h ago` if (days < 7) return `${days}d ago` return format(timestamp, 'MMMM d, yyyy h:mm a') } catch (error) { console.error('Error parsing time', error, 'timestamp', timestamp) return '' } } export const formatDuration = (seconds, showSeconds = true) => { const totalSeconds = Math.floor(seconds) if (totalSeconds < 60) return `${totalSeconds}s` if (totalSeconds < 3600) return `${Math.floor(totalSeconds / 60)}m ${totalSeconds % 60}s` const hours = Math.floor(totalSeconds / 3600) const mins = Math.floor((totalSeconds % 3600) / 60) const secs = totalSeconds % 60 return `${hours}h ${mins}m ${showSeconds ? `${secs}s` : ''}` }