formatDateTimeErrors example

if (\DateTimeInterface::class === $type) {
                $type = \DateTimeImmutable::class;
            }

            if (null !== $dateTimeFormat) {
                if (false !== $object = $type::createFromFormat($dateTimeFormat$data$timezone)) {
                    return $object;
                }

                $dateTimeErrors = $type::getLastErrors();

                throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('Parsing datetime string "%s" using format "%s" resulted in %d errors: ', $data$dateTimeFormat$dateTimeErrors['error_count'])."\n".implode("\n", $this->formatDateTimeErrors($dateTimeErrors['errors']))$data[Type::BUILTIN_TYPE_STRING]$context['deserialization_path'] ?? null, true);
            }

            $defaultDateTimeFormat = $this->defaultContext[self::FORMAT_KEY] ?? null;

            if (null !== $defaultDateTimeFormat) {
                if (false !== $object = $type::createFromFormat($defaultDateTimeFormat$data$timezone)) {
                    return $object;
                }
            }

            return new $type($data$timezone);
        }
try {
            if (null !== $dateTimeFormat) {
                $object = \DateTime::class === $type ? \DateTime::createFromFormat($dateTimeFormat$data$timezone) : \DateTimeImmutable::createFromFormat($dateTimeFormat$data$timezone);

                if (false !== $object) {
                    return $object;
                }

                $dateTimeErrors = \DateTime::class === $type ? \DateTime::getLastErrors() : \DateTimeImmutable::getLastErrors();

                throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('Parsing datetime string "%s" using format "%s" resulted in %d errors: ', $data$dateTimeFormat$dateTimeErrors['error_count'])."\n".implode("\n", $this->formatDateTimeErrors($dateTimeErrors['errors']))$data[Type::BUILTIN_TYPE_STRING]$context['deserialization_path'] ?? null, true);
            }

            $defaultDateTimeFormat = $this->defaultContext[self::FORMAT_KEY] ?? null;

            if (null !== $defaultDateTimeFormat) {
                $object = \DateTime::class === $type ? \DateTime::createFromFormat($defaultDateTimeFormat$data$timezone) : \DateTimeImmutable::createFromFormat($defaultDateTimeFormat$data$timezone);

                if (false !== $object) {
                    return $object;
                }
            }

            
Home | Imprint | This part of the site doesn't use cookies.