twigphp/Twig · error · Twig\Error\RuntimeError

The date format " " does not exist, known formats are: " ".

Error message

The date format "%s" does not exist, known formats are: "%s".

What it means

createDateFormatter validates the $dateFormat argument against the known date formats exposed by IntlExtension::availableDateFormats(). Passing a dateFormat string that is not one of these known keys throws this RuntimeError listing the valid options.

Solutions

  1. Use only formats returned by IntlExtension::availableDateFormats() (the error message lists them)
  2. Fix the typo in the dateFormat argument in the template or PHP call
  3. If the value comes from configuration, validate it against availableDateFormats() before passing it
  4. Pass null for dateFormat and rely on pattern-based formatting instead

Example fix

// before
{{ date|format_datetime(dateFormat='longdate') }}
// after
{{ date|format_datetime(dateFormat='long') }}
Defensive patterns

Strategy: validation

Validate before calling

if (null !== $dateFormat && !isset(IntlExtension::availableDateFormats()[$dateFormat])) { throw new \InvalidArgumentException("Unknown date format $dateFormat"); }

Type guard

function isKnownDateFormat(?string $f): bool { return null === $f || isset(IntlExtension::availableDateFormats()[$f]); }

Try / catch

try { $out = $intl->formatDateTime($date, $dateFormat, $timeFormat); } catch (\Twig\Error\RuntimeError $e) { if (str_contains($e->getMessage(), 'date format')) { $out = $intl->formatDateTime($date, null, $timeFormat); } else { throw $e; } }

Prevention

When it happens

Trigger: Calling the format_datetime / format_date filters (via formatDateTime -> createDateFormatter) with a dateFormat value that is not a key of availableDateFormats() — e.g. 'long_date', 'ISO8601', or a typo like 'meduim'.

Common situations: Typos in template filter arguments; copying ICU constant names (like 'FULL') that differ from the extension's accepted keys; dynamically passing user- or config-supplied format names without validation.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of twigphp/Twig@a414c3a491 (2026-09-13). Data as JSON: /api/errors/54fbf9c31cc360db. Report an issue: GitHub.

Appendix: source

Thrown at extra/intl-extra/IntlExtension.php:467

    {
        if (!class_exists('IntlListFormatter')) {
            throw new RuntimeError('The "format_list" filter requires the "IntlListFormatter" class, which is available since PHP 8.5.');
        }

        $formatter = $this->createListFormatter($locale, $type, $width);
        if (false === $ret = $formatter->format($strings)) {
            throw new RuntimeError(\sprintf('Unable to format the given list: %s', $formatter->getErrorMessage()));
        }

        return $ret;
    }

    private function createDateFormatter(?string $locale, ?string $dateFormat, ?string $timeFormat, string $pattern, ?\DateTimeZone $timezone, ?string $calendar): \IntlDateFormatter
    {
        $dateFormats = self::availableDateFormats();

        if (null !== $dateFormat && !isset($dateFormats[$dateFormat])) {
            throw new RuntimeError(\sprintf('The date format "%s" does not exist, known formats are: "%s".', $dateFormat, implode('", "', array_keys($dateFormats))));
        }

        if (null !== $timeFormat && !isset(self::TIME_FORMATS[$timeFormat])) {
            throw new RuntimeError(\sprintf('The time format "%s" does not exist, known formats are: "%s".', $timeFormat, implode('", "', array_keys(self::TIME_FORMATS))));
        }

        if (null === $locale) {
            if ($this->dateFormatterPrototype) {
                $locale = $this->dateFormatterPrototype->getLocale();
            }
            $locale = $locale ?: \Locale::getDefault();
        }

        $calendar = null === $calendar ? null : ('gregorian' === $calendar ? \IntlDateFormatter::GREGORIAN : \IntlDateFormatter::TRADITIONAL);

        $dateFormatValue = null === $dateFormat ? null : $dateFormats[$dateFormat];
        $timeFormatValue = null === $timeFormat ? null : self::TIME_FORMATS[$timeFormat];

View on GitHub (pinned to a414c3a491)