/**
 * Formats the given date as 'dd MMM yyyy'.
 * If the given date is null, returns null.
 *
 * @param {string | null} archiveDate - The date to format.
 * @return {string | null} The formatted date, or null if the given date is null.
 */
export function formatDate(archiveDate: string | null): string | null {
  let formattedArchiveDate = null;

  if (archiveDate) {
    const archiveDateObject = new Date(archiveDate);
    formattedArchiveDate = new Intl.DateTimeFormat('en-GB', {
      day: '2-digit',
      month: 'short',
      year: 'numeric',
    }).format(archiveDateObject);
  }

  return formattedArchiveDate;
}
