diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php index 4d7eed8b0c..8d73404b5d 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php @@ -172,7 +172,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer $calendar = $this->calendar; $pattern = $this->pattern; - $intlDateFormatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, $timezone, $calendar, $pattern); + $intlDateFormatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, $timezone, $calendar, $pattern ?? ''); // new \intlDateFormatter may return null instead of false in case of failure, see https://bugs.php.net/66323 if (!$intlDateFormatter) { diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index e446151d2a..0a20d94e66 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -51,14 +51,14 @@ class DateType extends AbstractType $dateFormat = \is_int($options['format']) ? $options['format'] : self::DEFAULT_FORMAT; $timeFormat = \IntlDateFormatter::NONE; $calendar = \IntlDateFormatter::GREGORIAN; - $pattern = \is_string($options['format']) ? $options['format'] : null; + $pattern = \is_string($options['format']) ? $options['format'] : ''; if (!\in_array($dateFormat, self::$acceptedFormats, true)) { throw new InvalidOptionsException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom format.'); } if ('single_text' === $options['widget']) { - if (null !== $pattern && false === strpos($pattern, 'y') && false === strpos($pattern, 'M') && false === strpos($pattern, 'd')) { + if ('' !== $pattern && false === strpos($pattern, 'y') && false === strpos($pattern, 'M') && false === strpos($pattern, 'd')) { throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" or "d". Its current value is "%s".', $pattern)); } @@ -71,7 +71,7 @@ class DateType extends AbstractType $pattern )); } else { - if (null !== $pattern && (false === strpos($pattern, 'y') || false === strpos($pattern, 'M') || false === strpos($pattern, 'd'))) { + if ('' !== $pattern && (false === strpos($pattern, 'y') || false === strpos($pattern, 'M') || false === strpos($pattern, 'd'))) { throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" and "d". Its current value is "%s".', $pattern)); } diff --git a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php index d77c094117..317510c236 100644 --- a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php +++ b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php @@ -145,6 +145,10 @@ abstract class IntlDateFormatter $this->datetype = null !== $datetype ? $datetype : self::FULL; $this->timetype = null !== $timetype ? $timetype : self::FULL; + if ('' === ($pattern ?? '')) { + $pattern = $this->getDefaultPattern(); + } + $this->setPattern($pattern); $this->setTimeZone($timezone); } @@ -485,7 +489,7 @@ abstract class IntlDateFormatter /** * Set the formatter's pattern. * - * @param string|null $pattern A pattern string in conformance with the ICU IntlDateFormatter documentation + * @param string $pattern A pattern string in conformance with the ICU IntlDateFormatter documentation * * @return bool true on success or false on failure * @@ -494,11 +498,7 @@ abstract class IntlDateFormatter */ public function setPattern($pattern) { - if (null === $pattern) { - $pattern = $this->getDefaultPattern(); - } - - $this->pattern = $pattern; + $this->pattern = (string) $pattern; return true; }