/**
 * German date/time formatting helpers.
 * Used across client and server.
 */

/**
 * Format date as DD.MM.YYYY
 */
export function formatDate(date: Date): string {
  const d = new Date(date);
  return d.toLocaleDateString("de-DE", {
    day: "2-digit",
    month: "2-digit",
    year: "numeric",
  });
}

/**
 * Format time as HH:MM
 */
export function formatTime(date: Date): string {
  const d = new Date(date);
  return d.toLocaleTimeString("de-DE", {
    hour: "2-digit",
    minute: "2-digit",
  });
}

/**
 * Format date and time as DD.MM.YYYY HH:MM:SS
 */
export function formatDateTime(date: Date): string {
  const d = new Date(date);
  return `${formatDate(d)} ${d.toLocaleTimeString("de-DE")}`;
}

/**
 * Format date with weekday as "Mo., DD.MM.YYYY"
 */
export function formatDateWithWeekday(date: Date): string {
  const d = new Date(date);
  return d.toLocaleDateString("de-DE", {
    weekday: "short",
    day: "2-digit",
    month: "2-digit",
    year: "numeric",
  });
}

/**
 * Format date as DD.MM. (short, without year)
 */
export function formatDateShort(date: Date): string {
  const d = new Date(date);
  return d.toLocaleDateString("de-DE", {
    day: "2-digit",
    month: "2-digit",
  });
}

/**
 * Format date with weekday short as "Mo., DD.MM."
 */
export function formatDateWithWeekdayShort(date: Date): string {
  const d = new Date(date);
  return d.toLocaleDateString("de-DE", {
    weekday: "short",
    day: "2-digit",
    month: "2-digit",
  });
}

// Format date as YYYY-MM-DD for exception date comparison
export function formatDateKey(date: Date): string {
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, "0");
  const day = String(date.getDate()).padStart(2, "0");
  return `${year}-${month}-${day}`;
}
