/**
 * The backend always interprets bare datetime strings (no timezone suffix) as East African
 * Time (EAT, UTC+3) and stores everything as UTC — see parseEthiopianTime() in
 * apps/edr-passenger-api/src/common/utils/timezone.utils.ts. These mirror that on the frontend
 * so `<input type="datetime-local">` fields round-trip correctly regardless of the browser's
 * own local timezone.
 */

/** Parse a datetime-local string ("YYYY-MM-DDTHH:mm") as EAT (UTC+3) and return a UTC ISO string. */
export function eatLocalToISO(local: string): string {
  if (!local) return '';
  return new Date(local + ':00+03:00').toISOString();
}

/** Convert a UTC ISO string/Date to a datetime-local value ("YYYY-MM-DDTHH:mm") in EAT (UTC+3). */
export function isoToEATLocal(iso: string | Date): string {
  if (!iso) return '';
  const utcMs = new Date(iso).getTime();
  const eatMs = utcMs + 3 * 60 * 60 * 1000;
  return new Date(eatMs).toISOString().slice(0, 16);
}
