diff --git a/.github/workflows/intl-data-tests.yml b/.github/workflows/intl-data-tests.yml index 0925858432..0ca0322281 100644 --- a/.github/workflows/intl-data-tests.yml +++ b/.github/workflows/intl-data-tests.yml @@ -15,7 +15,7 @@ defaults: jobs: tests: name: Tests (intl-data) - runs-on: ubuntu-latest + runs-on: Ubuntu-20.04 steps: - name: Checkout diff --git a/.github/workflows/phpunit-bridge.yml b/.github/workflows/phpunit-bridge.yml index 8fa97980ff..b503ce48d8 100644 --- a/.github/workflows/phpunit-bridge.yml +++ b/.github/workflows/phpunit-bridge.yml @@ -15,7 +15,7 @@ defaults: jobs: lint: name: Lint - runs-on: ubuntu-latest + runs-on: Ubuntu-20.04 steps: - name: Checkout diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bdcb488e63..d8e6586e5b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,7 +11,7 @@ defaults: jobs: integration: name: Integration - runs-on: ubuntu-latest + runs-on: Ubuntu-20.04 strategy: matrix: diff --git a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php index a47fd76b45..7a02d18276 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php @@ -96,7 +96,7 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa $dateIntervalFormat = substr($dateIntervalFormat, 2); break; } - $valuePattern = '/^'.$signPattern.preg_replace('/%([yYmMdDhHiIsSwW])(\w)/', '(?P<$1>\d+)$2', $dateIntervalFormat).'$/'; + $valuePattern = '/^'.$signPattern.preg_replace('/%([yYmMdDhHiIsSwW])(\w)/', '(?:(?P<$1>\d+)$2)?', preg_replace('/(T.*)$/', '($1)?', $dateIntervalFormat)).'$/'; if (!preg_match($valuePattern, $data)) { throw new UnexpectedValueException(sprintf('Value "%s" contains intervals not accepted by format "%s".', $data, $dateIntervalFormat)); } diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php index df87fa7df6..e45a6b042f 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php @@ -104,6 +104,14 @@ class DateIntervalNormalizerTest extends TestCase $this->assertDateIntervalEquals($this->getInterval($output), $normalizer->denormalize($input, \DateInterval::class)); } + public function testDenormalizeIntervalsWithOmittedPartsBeingZero() + { + $normalizer = new DateIntervalNormalizer(); + + $this->assertDateIntervalEquals($this->getInterval('P3Y2M4DT0H0M0S'), $normalizer->denormalize('P3Y2M4D', \DateInterval::class)); + $this->assertDateIntervalEquals($this->getInterval('P0Y0M0DT12H34M0S'), $normalizer->denormalize('PT12H34M', \DateInterval::class)); + } + public function testDenormalizeExpectsString() { $this->expectException(InvalidArgumentException::class);