{"record":{"id":"54fbf9c31cc360db","repo":"twigphp/Twig","slug":"the-date-format-s-does-not-exist-known-formats-are-s","errorCode":null,"errorMessage":"The date format \"%s\" does not exist, known formats are: \"%s\".","messagePattern":"The date format \"(.+?)\" does not exist, known formats are: \"(.+?)\"\\.","errorType":"exception","errorClass":"Twig\\Error\\RuntimeError","httpStatus":null,"severity":"error","filePath":"extra/intl-extra/IntlExtension.php","lineNumber":467,"sourceCode":"    {\n        if (!class_exists('IntlListFormatter')) {\n            throw new RuntimeError('The \"format_list\" filter requires the \"IntlListFormatter\" class, which is available since PHP 8.5.');\n        }\n\n        $formatter = $this->createListFormatter($locale, $type, $width);\n        if (false === $ret = $formatter->format($strings)) {\n            throw new RuntimeError(\\sprintf('Unable to format the given list: %s', $formatter->getErrorMessage()));\n        }\n\n        return $ret;\n    }\n\n    private function createDateFormatter(?string $locale, ?string $dateFormat, ?string $timeFormat, string $pattern, ?\\DateTimeZone $timezone, ?string $calendar): \\IntlDateFormatter\n    {\n        $dateFormats = self::availableDateFormats();\n\n        if (null !== $dateFormat && !isset($dateFormats[$dateFormat])) {\n            throw new RuntimeError(\\sprintf('The date format \"%s\" does not exist, known formats are: \"%s\".', $dateFormat, implode('\", \"', array_keys($dateFormats))));\n        }\n\n        if (null !== $timeFormat && !isset(self::TIME_FORMATS[$timeFormat])) {\n            throw new RuntimeError(\\sprintf('The time format \"%s\" does not exist, known formats are: \"%s\".', $timeFormat, implode('\", \"', array_keys(self::TIME_FORMATS))));\n        }\n\n        if (null === $locale) {\n            if ($this->dateFormatterPrototype) {\n                $locale = $this->dateFormatterPrototype->getLocale();\n            }\n            $locale = $locale ?: \\Locale::getDefault();\n        }\n\n        $calendar = null === $calendar ? null : ('gregorian' === $calendar ? \\IntlDateFormatter::GREGORIAN : \\IntlDateFormatter::TRADITIONAL);\n\n        $dateFormatValue = null === $dateFormat ? null : $dateFormats[$dateFormat];\n        $timeFormatValue = null === $timeFormat ? null : self::TIME_FORMATS[$timeFormat];\n","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/extra/intl-extra/IntlExtension.php#L449-L485","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","solutions":["Use only formats returned by IntlExtension::availableDateFormats() (the error message lists them)","Fix the typo in the dateFormat argument in the template or PHP call","If the value comes from configuration, validate it against availableDateFormats() before passing it","Pass null for dateFormat and rely on pattern-based formatting instead"],"exampleFix":"// before\n{{ date|format_datetime(dateFormat='longdate') }}\n// after\n{{ date|format_datetime(dateFormat='long') }}","handlingStrategy":"validation","validationCode":"if (null !== $dateFormat && !isset(IntlExtension::availableDateFormats()[$dateFormat])) { throw new \\InvalidArgumentException(\"Unknown date format $dateFormat\"); }","typeGuard":"function isKnownDateFormat(?string $f): bool { return null === $f || isset(IntlExtension::availableDateFormats()[$f]); }","tryCatchPattern":"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; } }","preventionTips":["Whitelist date formats from availableDateFormats() in config","Add unit tests for every template filter format argument","Never pass raw user input as dateFormat"],"tags":["php","intl","date","invalid-argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}