{"record":{"id":"6f5df394eb24b5c6","repo":"twigphp/Twig","slug":"the-time-format-s-does-not-exist-known-formats-are-s","errorCode":null,"errorMessage":"The time format \"%s\" does not exist, known formats are: \"%s\".","messagePattern":"The time format \"(.+?)\" does not exist, known formats are: \"(.+?)\"\\.","errorType":"exception","errorClass":"Twig\\Error\\RuntimeError","httpStatus":null,"severity":"error","filePath":"extra/intl-extra/IntlExtension.php","lineNumber":471,"sourceCode":"\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\n        if ($this->dateFormatterPrototype) {\n            if (null === $dateFormatValue && false !== $prototypeDateFormat = $this->dateFormatterPrototype->getDateType()) {\n                $dateFormatValue = $prototypeDateFormat;\n            }","sourceCodeStart":453,"sourceCodeEnd":489,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/extra/intl-extra/IntlExtension.php#L453-L489","documentation":"createDateFormatter validates the $timeFormat argument against the IntlExtension::TIME_FORMATS constant. Passing an unrecognized timeFormat key throws this RuntimeError listing the accepted time format names.","triggerScenarios":"Calling format_datetime / format_time (via formatDateTime -> createDateFormatter) with a timeFormat string not present in TIME_FORMATS — e.g. 'full24', 'short_time', or a misspelled 'meduim'.","commonSituations":"Typos in template arguments; assuming ICU or Java style constant names work; passing config-driven time format strings that were never validated against TIME_FORMATS.","solutions":["Use only keys defined in IntlExtension::TIME_FORMATS (the message enumerates them: none, short, medium, long, full)","Correct the typo in the timeFormat argument","Validate config-supplied time formats against TIME_FORMATS before rendering","Omit timeFormat (pass null) and use a custom pattern instead"],"exampleFix":"// before\n{{ date|format_datetime(timeFormat='shorttime') }}\n// after\n{{ date|format_datetime(timeFormat='short') }}","handlingStrategy":"validation","validationCode":"if (null !== $timeFormat && !in_array($timeFormat, IntlExtension::TIME_FORMATS, true) && !isset(IntlExtension::TIME_FORMATS[$timeFormat])) { throw new \\InvalidArgumentException(\"Unknown time format $timeFormat\"); }","typeGuard":"function isKnownTimeFormat(?string $f): bool { return null === $f || isset(IntlExtension::TIME_FORMATS[$f]); }","tryCatchPattern":"try { $out = $intl->formatDateTime($date, $dateFormat, $timeFormat); } catch (\\Twig\\Error\\RuntimeError $e) { if (str_contains($e->getMessage(), 'time format')) { $out = $intl->formatDateTime($date, $dateFormat, null); } else { throw $e; } }","preventionTips":["Whitelist time formats from TIME_FORMATS in config","Add tests for filter argument combos","Avoid free-form string time formats from user input"],"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"}