export function formatDate(value?: string) {
  if (!value) {
    return 'To be confirmed';
  }

  return new Intl.DateTimeFormat('en-GB', {
    day: '2-digit',
    month: 'short',
    year: 'numeric',
  }).format(new Date(value));
}

export function formatDateTime(value?: string) {
  if (!value) {
    return 'To be confirmed';
  }

  if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
    return formatDate(value);
  }

  return new Intl.DateTimeFormat('en-GB', {
    day: '2-digit',
    month: 'short',
    year: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
  }).format(new Date(value));
}

export function formatWeekday(value?: string) {
  if (!value) {
    return 'TBC';
  }

  return new Intl.DateTimeFormat('en-GB', {
    weekday: 'long',
  }).format(new Date(value));
}

export function formatTime(value?: string) {
  if (!value) {
    return 'Time TBC';
  }

  if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
    return '';
  }

  return new Intl.DateTimeFormat('en-GB', {
    hour: '2-digit',
    minute: '2-digit',
  }).format(new Date(value));
}
