code: def babel_format_date(
      date: datetime,
      format: str,
      locale: str,
      formatter: Callable = babel.dates.format_date,
  ) -> str:
      # Check if we have the tzinfo attribute. If not we cannot do any time
      # related formats.
      if not hasattr(date, "tzinfo"):
          formatter = babel.dates.format_date
  
      try:
          return formatter(date, format, locale=locale)
      except (ValueError, babel.core.UnknownLocaleError):
          # fallback to English
          return formatter(date, format, locale="en")
      except AttributeError:
          logger.warning(
              __(
                  "Invalid date format. Quote the string by single quote "
                  "if you want to output it directly: %s"
              ),
              format,
          )
          return format
  
imports: from __future__ import annotations
  import os
  import re
  from datetime import datetime, timezone
  from os import path
  from typing import TYPE_CHECKING, Callable, NamedTuple
  import babel.dates
  from babel.messages.mofile import write_mo
  from babel.messages.pofile import read_po
  from sphinx.errors import SphinxError
  from sphinx.locale import __
  from sphinx.util import logging
  from sphinx.util.osutil import SEP, canon_path, relpath
label_desc: Use image node_id 2 for calling a global function with example usage: babel_format_date(date, format, locale, formatter) and returns: formatter, formatter, format