export function toIsoSqlUTC(d: Date = new Date()): string {
  return d.toISOString().replace('T', ' ').replace('Z', '');
}

export function normalizeTime(input: string | null | undefined): string | null {
  const s = (input ?? '').trim();
  const m = /^(\d{1,2}):(\d{1,2})$/.exec(s);
  if (!m) return null;
  const h = Number(m[1]);
  const min = Number(m[2]);
  if (!Number.isFinite(h) || !Number.isFinite(min)) return null;
  if (h < 0 || h > 23 || min < 0 || min > 59) return null;
  const hh = String(h).padStart(2, '0');
  const mm = String(min).padStart(2, '0');
  return `${hh}:${mm}`;
}
