export function formatDate(yyyymmdd: string): string { if (!/^\d{8}$/.test(yyyymmdd)) return yyyymmdd; return `${yyyymmdd.slice(0, 4)}-${yyyymmdd.slice(4, 6)}-${yyyymmdd.slice(6, 8)}`; } // Whole days between an upload date ("YYYYMMDD") and now. Returns null on a // missing/malformed date. Used to flag VODs past their platform's retention // window (see vodExpiry). Interpreted as UTC midnight to match yt-dlp's // upload_date (a date, not a timestamp). export function daysSince(yyyymmdd: string | undefined | null): number | null { if (!yyyymmdd || !/^\d{8}$/.test(yyyymmdd)) return null; const y = Number(yyyymmdd.slice(0, 4)); const m = Number(yyyymmdd.slice(4, 6)); const d = Number(yyyymmdd.slice(6, 8)); const then = Date.UTC(y, m - 1, d); if (Number.isNaN(then)) return null; return Math.floor((Date.now() - then) / 86_400_000); } export function formatBytes(bytes: number): string { if (!Number.isFinite(bytes)) return "∞"; if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`; } export function formatDuration(seconds: number): string { if (!seconds) return ""; const h = Math.floor(seconds / 3600); const m = Math.floor((seconds % 3600) / 60); const s = Math.floor(seconds % 60); const mm = String(m).padStart(2, "0"); const ss = String(s).padStart(2, "0"); return h > 0 ? `${h}:${mm}:${ss}` : `${m}:${ss}`; }