core/modules/hal/src/Normalizer/TimestampItemNormalizer.php | 2 +- core/modules/serialization/src/Normalizer/DateTimeNormalizer.php | 6 ------ .../serialization/src/Normalizer/TimestampItemNormalizer.php | 2 +- .../tests/src/Unit/Normalizer/DateTimeNormalizerTest.php | 2 +- .../tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php | 2 +- 5 files changed, 4 insertions(+), 10 deletions(-) diff --git a/core/modules/hal/src/Normalizer/TimestampItemNormalizer.php b/core/modules/hal/src/Normalizer/TimestampItemNormalizer.php index 2cda0fa..e3d00f1 100644 --- a/core/modules/hal/src/Normalizer/TimestampItemNormalizer.php +++ b/core/modules/hal/src/Normalizer/TimestampItemNormalizer.php @@ -39,7 +39,7 @@ protected function normalizedFieldValues(FieldItemInterface $field_item, $format */ protected function constructValue($data, $context) { if (!empty($data['format'])) { - $context['datetime_format'] = $data['format']; + $context['datetime_allowed_formats'] = [$data['format']]; } return ['value' => $this->serializer->denormalize($data['value'], Timestamp::class, NULL, $context)]; } diff --git a/core/modules/serialization/src/Normalizer/DateTimeNormalizer.php b/core/modules/serialization/src/Normalizer/DateTimeNormalizer.php index e84571a..a6353a0 100644 --- a/core/modules/serialization/src/Normalizer/DateTimeNormalizer.php +++ b/core/modules/serialization/src/Normalizer/DateTimeNormalizer.php @@ -68,12 +68,6 @@ protected function getNormalizationTimezone() { * {@inheritdoc} */ public function denormalize($data, $class, $format = NULL, array $context = []) { - // First check for a provided format, and if provided, create \DateTime - // object using it. - if (!empty($context['datetime_format'])) { - return \DateTime::createFromFormat($context['datetime_format'], $data); - } - // Loop through the allowed formats and create a \DateTime from the // input data if it matches the defined pattern. Since the formats are // unambiguous (i.e., they reference an absolute time with a defined time diff --git a/core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php b/core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php index cf0f8ac..9349c4e 100644 --- a/core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php +++ b/core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php @@ -39,7 +39,7 @@ public function normalize($object, $format = NULL, array $context = []) { */ protected function constructValue($data, $context) { if (!empty($data['format'])) { - $context['datetime_format'] = $data['format']; + $context['datetime_allowed_formats'] = [$data['format']]; } return ['value' => $this->serializer->denormalize($data['value'], Timestamp::class, NULL, $context)]; } diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php index 570784b..00dbbb2 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php @@ -143,7 +143,7 @@ public function providerTestDenormalizeValidFormats() { * @dataProvider providerTestDenormalizeUserFormats */ public function testDenormalizeUserFormats($normalized, $format, $expected) { - $denormalized = $this->normalizer->denormalize($normalized, DateTimeInterface::class, NULL, ['datetime_format' => $format]); + $denormalized = $this->normalizer->denormalize($normalized, DateTimeInterface::class, NULL, ['datetime_allowed_formats' => [$format]]); $this->assertSame(0, $denormalized->getTimestamp() - $expected->getTimestamp()); $this->assertEquals($expected, $denormalized); } diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php index 8575501..4d01279 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php @@ -122,7 +122,7 @@ public function testDenormalize() { $context = [ 'target_instance' => $timestamp_item->reveal(), - 'datetime_format' => \DateTime::RFC3339, + 'datetime_allowed_formats' => [\DateTime::RFC3339], ]; // Mock Serializer service, to assert that the Timestamp @DataType