export const formatDuration = (totalSeconds: number) => { const totalMinutes = Math.max(1, Math.ceil(totalSeconds / 60)) const hours = Math.floor(totalMinutes / 60) const minutes = totalMinutes % 60 if (hours === 0) return `${minutes} min` if (minutes === 0) return `${hours} hr` return `${hours} hr ${minutes} min` } const startOfDay = (date: Date) => new Date(date.getFullYear(), date.getMonth(), date.getDate()) export const formatEtaClock = (etaSeconds: number, now = new Date()) => { const target = new Date(now.getTime() + etaSeconds * 1000) const time = target.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) const dayDiff = Math.round( (startOfDay(target).getTime() - startOfDay(now).getTime()) / 86_400_000, ) if (dayDiff === 0) return `today, ${time}` if (dayDiff === 1) return `tomorrow, ${time}` return `${target.toLocaleDateString([], { weekday: 'long' })}, ${time}` } const ABSOLUTE_TIME_THRESHOLD_SECONDS = 3 * 60 * 60 export const formatEtaMessage = (etaSeconds: number, now = new Date()) => etaSeconds > ABSOLUTE_TIME_THRESHOLD_SECONDS ? `Ready ${formatEtaClock(etaSeconds, now)}` : `Ready in about ${formatDuration(etaSeconds)}`