Files
SAE-BUT2-frontend/src/utils/date/formatTime.ts
T

13 lines
382 B
TypeScript

export default function formatTime(d: string | Date | number | null | undefined): string {
if (!d) return "Heure inconnue";
const date = d instanceof Date ? d : new Date(d);
if (isNaN(date.getTime())) return "Heure invalide";
const hh = String(date.getUTCHours()).padStart(2, "0");
const min = String(date.getUTCMinutes()).padStart(2, "0");
return `${hh}:${min}`;
}