{"record":{"id":"e1ec41adcf3a3e0b","repo":"twigphp/Twig","slug":"unable-to-format-the-given-date","errorCode":null,"errorMessage":"Unable to format the given date.","messagePattern":"Unable to format the given date\\.","errorType":"exception","errorClass":"Twig\\Error\\RuntimeError","httpStatus":null,"severity":"error","filePath":"extra/intl-extra/IntlExtension.php","lineNumber":421,"sourceCode":"\n    /**\n     * @param \\DateTimeInterface|string|null  $date     A date or null to use the current time\n     * @param \\DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged\n     */\n    public function formatDateTime(Environment $env, $date, ?string $dateFormat = null, ?string $timeFormat = null, string $pattern = '', $timezone = null, ?string $calendar = null, ?string $locale = null): string\n    {\n        $date = $env->getExtension(CoreExtension::class)->convertDate($date, $timezone);\n\n        $formatterTimezone = $timezone;\n        if (null === $formatterTimezone || false === $formatterTimezone) {\n            $formatterTimezone = $date->getTimezone();\n        } elseif (\\is_string($formatterTimezone)) {\n            $formatterTimezone = new \\DateTimeZone($timezone);\n        }\n        $formatter = $this->createDateFormatter($locale, $dateFormat, $timeFormat, $pattern, $formatterTimezone, $calendar);\n\n        if (false === $ret = $formatter->format($date)) {\n            throw new RuntimeError('Unable to format the given date.');\n        }\n\n        return $ret;\n    }\n\n    /**\n     * @param \\DateTimeInterface|string|null  $date     A date or null to use the current time\n     * @param \\DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged\n     */\n    public function formatDate(Environment $env, $date, ?string $dateFormat = null, string $pattern = '', $timezone = null, ?string $calendar = null, ?string $locale = null): string\n    {\n        return $this->formatDateTime($env, $date, $dateFormat, 'none', $pattern, $timezone, $calendar, $locale);\n    }\n\n    /**\n     * @param \\DateTimeInterface|string|null  $date     A date or null to use the current time\n     * @param \\DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged\n     */","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/extra/intl-extra/IntlExtension.php#L403-L439","documentation":"formatDateTime() (used internally by formatDate/formatTime) wraps IntlDateFormatter::format(); a false return means ICU could not render the date for the given pattern/calendar/locale, so the extension throws this RuntimeError.","triggerScenarios":"Formatting values that are not valid date/time inputs (empty string, invalid date strings), or incompatible pattern/calendar combinations (e.g. a pattern with non-Gregorian calendar), or a DateTimeImmutable/IntlDateFormatter mismatch via weird timezone data.","commonSituations":"'0000-00-00' legacy database dates passed straight to the filter; invalid user input; missing ICU locale data; pattern strings containing ICU-unsupported characters.","solutions":["Convert input to a DateTimeInterface first: new DateTimeImmutable($value) inside a validity check.","Filter out legacy sentinel dates like '0000-00-00' before formatting.","Validate the $pattern is a valid ICU date/time pattern.","Check installed ICU data (php --ri intl) for the target locale/calendar."],"exampleFix":"// before\n{{ row.birthday|format_date('short') }}\n// after\n{% if row.birthday and row.birthday != '0000-00-00' %}{{ row.birthday|date('Y-m-d')|format_date('short') }}{% endif %}","handlingStrategy":"validation","validationCode":"try { $date = $date instanceof \\DateTimeInterface ? $date : new \\DateTimeImmutable((string)$date); } catch (\\Exception $e) { /* skip formatting */ }","typeGuard":"function isFormattableDate(mixed $d): bool { try { return $d instanceof \\DateTimeInterface || (is_string($d) && '' !== $d && false !== strtotime($d)); } catch (\\Exception) { return false; } }","tryCatchPattern":"try { $s = format_date($value, 'short'); } catch (Twig\\Error\\RuntimeError $e) { $s = '—'; }","preventionTips":["Convert strings to DateTimeInterface before formatting","Filter legacy sentinel dates ('0000-00-00') at the data layer","Verify ICU locale data for non-Gregorian calendars/patterns"],"tags":["intl","date-format","formatter"],"backgroundTag":"invalid-date-format","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"}