// Takes either 6 or 8 characters string (YYYYMMDD) and formats it to ISO standard (YYYY-MM-DD).
export function formatToIsoString(date: string): string {
  if (date.length === 6) {
    return `${date.substring(0, 4)}-${date.substring(4)}`;
  } else if (date.length === 8) {
    return `${date.substring(0, 4)}-${date.substring(4, 6)}-${date.substring(6)}`;
  }

  return date;
}

export function formatToDate(date: string): Date {
  const year = date.substring(0, 4);
  const month = date.substring(4, 6) || '01';
  const day = date.substring(6, 8) || '01';

  return new Date(`${year}-${month}-${day}`);
}
