Merge branch '4.4' into 5.2

* 4.4:
  Specify that we run CI on Ubuntu-20.04
  zero parts can be omitted in date interval input
This commit is contained in:
Alexander M. Turek 2021-03-02 13:14:02 +01:00
commit 5985199754
5 changed files with 12 additions and 4 deletions

View File

@ -15,7 +15,7 @@ defaults:
jobs:
tests:
name: Tests (intl-data)
runs-on: ubuntu-latest
runs-on: Ubuntu-20.04
steps:
- name: Checkout

View File

@ -15,7 +15,7 @@ defaults:
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
runs-on: Ubuntu-20.04
steps:
- name: Checkout

View File

@ -11,7 +11,7 @@ defaults:
jobs:
integration:
name: Integration
runs-on: ubuntu-latest
runs-on: Ubuntu-20.04
strategy:
matrix:

View File

@ -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));
}

View File

@ -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);