twigphp/Twig · error · Twig\Error\RuntimeError
The time format " " does not exist, known formats are: " ".
Error message
The time format "%s" does not exist, known formats are: "%s".
What it means
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.
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
Example fix
// before
{{ date|format_datetime(timeFormat='shorttime') }}
// after
{{ date|format_datetime(timeFormat='short') }} Defensive patterns
Strategy: validation
Validate before calling
if (null !== $timeFormat && !in_array($timeFormat, IntlExtension::TIME_FORMATS, true) && !isset(IntlExtension::TIME_FORMATS[$timeFormat])) { throw new \InvalidArgumentException("Unknown time format $timeFormat"); } Type guard
function isKnownTimeFormat(?string $f): bool { return null === $f || isset(IntlExtension::TIME_FORMATS[$f]); } Try / catch
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; } } Prevention
- Whitelist time formats from TIME_FORMATS in config
- Add tests for filter argument combos
- Avoid free-form string time formats from user input
When it happens
Trigger: 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'.
Common situations: 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.
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
- The date format " " does not exist, known formats are: " ".
- The style " " does not exist, known styles are: " ".
- The number formatter attribute
- The list type " " does not exist, known types are: " ".
- The list width " " does not exist, known widths are: " ".
AI-assisted analysis of twigphp/Twig@a414c3a491 (2026-09-13).
Data as JSON: /api/errors/6f5df394eb24b5c6.
Report an issue: GitHub.
Appendix: source
Thrown at extra/intl-extra/IntlExtension.php:471
$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];
if ($this->dateFormatterPrototype) {
if (null === $dateFormatValue && false !== $prototypeDateFormat = $this->dateFormatterPrototype->getDateType()) {
$dateFormatValue = $prototypeDateFormat;
}View on GitHub (pinned to a414c3a491)