export const formatDateToYYYYMMdd = (utcDateString: string | Date) => {
  const date = new Date(utcDateString);

  const localYear = date.getFullYear();
  const localMonth = date.getMonth() + 1; // Months are 0-indexed
  const localDay = date.getDate();

  const localDateFormatted = `${localYear}-${String(localMonth).padStart(2, "0")}-${String(localDay).padStart(2, "0")}`;

  return localDateFormatted;
};

export const formatDateToddMMYYYY = (
  utcDateString: string | Date,
  separator?: string,
) => {
  const sp = separator ?? "/";
  const date = new Date(utcDateString);

  const localYear = date.getFullYear();
  const localMonth = date.getMonth() + 1; // Months are 0-indexed
  const localDay = date.getDate();

  const localDateFormatted = `${String(localDay).padStart(2, "0")}${sp}${String(localMonth).padStart(2, "0")}${sp}${localYear}`;

  return localDateFormatted;
};

export function areDatesEqualWithoutTime(date1: string, date2: string) {
  const d1 = new Date(date1);
  const d2 = new Date(date2);

  d1.setHours(0, 0, 0, 0);
  d2.setHours(0, 0, 0, 0);

  return d1.getTime() === d2.getTime();
}
