import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";

dayjs.extend(utc);
dayjs.extend(timezone);

const HK = "Asia/Hong_Kong";

/**
 * Formats an ISO-8601 instant (e.g. Java `Instant.toString()`) for Hong Kong (GMT+8).
 */
export function formatHongKongDateTime(value: string | null | undefined): string {
  if (value == null || value === "") return "—";
  const ms = Date.parse(value);
  if (Number.isNaN(ms)) return value;
  return dayjs.utc(ms).tz(HK).format("YYYY-MM-DD HH:mm:ss [HKT]");
}
