All files / utils formatDate.ts

86.95% Statements 20/23
85.71% Branches 6/7
100% Functions 2/2
88.88% Lines 16/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44              5x 20x   10x 10x 10x 9x                         5x 21x   11x 11x 11x   3x 3x 3x   3x   3x        
/**
 * Formate une date en français avec le jour de la semaine, le jour et le mois
 * @param dateString - La date au format string (optionnel)
 * @returns La date formatée en français ou "Date Inconnue" si non fournie
 * @example
 * formatDateFr("2024-07-26") // "vendredi 26 juillet"
 */
export function formatDateFr(dateString?: string): string {
  if (!dateString) return "Date Inconnue";
 
  try {
    const date = new Date(dateString);
    if (isNaN(date.getTime())) return "Date Inconnue";
    return new Intl.DateTimeFormat("fr-FR", { weekday: "long", day: "numeric", month: "long" }).format(date);
  } catch {
    return "Date Inconnue";
  }
}
 
/**
 * Formate une heure au format français (ex: 14h30)
 * @param heure - L'heure au format HH:MM (optionnel)
 * @returns L'heure formatée ou "Horaire inconnu" si non fournie
 * @example
 * formatHeure("14:30") // "14h30"
 */
export function formatHeure(heure?: string): string {
  if (!heure) return "Horaire inconnu";
 
  try {
    const parts = heure.split(":");
    if (parts.length !== 2) return "Horaire inconnu";
 
    const [h, m] = parts;
    const hours = parseInt(h, 10);
    const minutes = parseInt(m, 10);
 
    Iif (isNaN(hours) || isNaN(minutes)) return "Horaire inconnu";
 
    return `${hours}h${m}`;
  } catch {
    return "Horaire inconnu";
  }
}