/** How long ago a moment was, in the short form the panels use. */ export function timeAgo(moment: Date | string | number, now: number = Date.now()): string { const value = new Date(moment); const minutes = Math.round((now - value.getTime()) / 60000); if (minutes < 1) return 'just now'; if (minutes < 60) return `${minutes} min ago`; const hours = Math.round(minutes / 60); if (hours < 24) return `${hours} h ago`; const days = Math.round(hours / 24); if (days < 7) return `${days} d ago`; /* * A scene version can be years old, and "Aug 6" alone puts two different years on * one day. The year shows only when it is not the current one, so a recent date * stays short. */ const sameYear = value.getFullYear() === new Date(now).getFullYear(); return value.toLocaleDateString( undefined, sameYear ? { month: 'short', day: 'numeric' } : { year: 'numeric', month: 'short', day: 'numeric' } ); }