tobogganSe connecter

starfleet-ui

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

12 lignes · 562 octetsBrut · Historique
1/** "2h 05m", "4m 12s", "38s" — compact remaining time until `iso`, never negative. */
2export function untilLabel(iso: string, now = Date.now()): string {
3 const total = Math.max(0, Math.round((new Date(iso).getTime() - now) / 1000));
4 const d = Math.floor(total / 86_400);
5 const h = Math.floor((total % 86_400) / 3600);
6 const m = Math.floor((total % 3600) / 60);
7 const s = total % 60;
8 if (d > 0) return `${d}d ${h}h`;
9 if (h > 0) return `${h}h ${String(m).padStart(2, '0')}m`;
10 if (m > 0) return `${m}m ${String(s).padStart(2, '0')}s`;
11 return `${s}s`;
12}