function formatDate(value, format, timezone, flatPickrInputFormat) {
  const dayjsDate = dayjs(value, flatPickrInputFormat || undefined);
  if (timezone === currentTimezone()) {
    // See if our format contains a "z" timezone character.
    if (format.match(/\s(z$|z\s)/)) {
      if (shouldHandleTimezone(timezone)) {
        return dayjsDate.tz(timezone).format(convertFormatToDayjs(format));
      }
      else {
        return dayjsDate.format(convertFormatToDayjs(format.replace(/\s(z$|z\s)/, '')));
      }
    }
    // Return the standard format.
    return dayjsDate.format(convertFormatToDayjs(format));
  }
  if (timezone === 'UTC') {
    const offset = offsetDate(dayjsDate.toDate(), 'UTC');
    return `${dayjs(offset.date).format(convertFormatToDayjs(format))} UTC`;
  }
  if (shouldHandleTimezone(timezone)) {
    return dayjsDate.tz(timezone).format(`${convertFormatToDayjs(format)} z`);
  }
  return dayjsDate.format(convertFormatToDayjs(format));
}
Format a date provided a value, format, and timezone object.
@param {string|Date} value - The value to format.
@param {string} format - The format to format the date to.
@param {string} timezone - The timezone to format the date to.
@param {string} flatPickrInputFormat - The format to use for flatpickr input.
@returns {string} - The formatted date.