.../Functional/EntityResource/EntityTest/EntityTestDateonlyTest.php | 2 +- core/modules/serialization/src/Normalizer/DateTimeNormalizer.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/modules/datetime/tests/src/Functional/EntityResource/EntityTest/EntityTestDateonlyTest.php b/core/modules/datetime/tests/src/Functional/EntityResource/EntityTest/EntityTestDateonlyTest.php index d7a8043..e8c71ef 100644 --- a/core/modules/datetime/tests/src/Functional/EntityResource/EntityTest/EntityTestDateonlyTest.php +++ b/core/modules/datetime/tests/src/Functional/EntityResource/EntityTest/EntityTestDateonlyTest.php @@ -146,7 +146,7 @@ protected function assertNormalizationEdgeCases($method, Url $url, array $reques $request_options[RequestOptions::BODY] = $this->serializer->encode($normalization, static::$format); $response = $this->request($method, $url, $request_options); - $message = "Unprocessable Entity: validation failed.\n{$fieldName}.0: The datetime value '{$value}' did not parse properly for the format 'Y-m-d'\n{$fieldName}.0.value: This value should be of the correct primitive type.\n"; + $message = "The specified date \"$value\" is not in an accepted format: \"Y-m-d\" (date-only)."; $this->assertResourceErrorResponse(422, $message, $response); } } diff --git a/core/modules/serialization/src/Normalizer/DateTimeNormalizer.php b/core/modules/serialization/src/Normalizer/DateTimeNormalizer.php index e0a72a9..3435af6 100644 --- a/core/modules/serialization/src/Normalizer/DateTimeNormalizer.php +++ b/core/modules/serialization/src/Normalizer/DateTimeNormalizer.php @@ -83,7 +83,8 @@ public function denormalize($data, $class, $format = NULL, array $context = []) : $this->allowedFormats; foreach ($allowed_formats as $format) { $date = \DateTime::createFromFormat($format, $data); - if ($date !== FALSE) { + $errors = \DateTime::getLastErrors(); + if ($date !== FALSE && empty($errors['errors']) && empty($errors['warnings'])) { return $date; } }