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:
commit
5985199754
|
@ -15,7 +15,7 @@ defaults:
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
tests:
|
||||||
name: Tests (intl-data)
|
name: Tests (intl-data)
|
||||||
runs-on: ubuntu-latest
|
runs-on: Ubuntu-20.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
|
|
|
@ -15,7 +15,7 @@ defaults:
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
name: Lint
|
name: Lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: Ubuntu-20.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
|
|
|
@ -11,7 +11,7 @@ defaults:
|
||||||
jobs:
|
jobs:
|
||||||
integration:
|
integration:
|
||||||
name: Integration
|
name: Integration
|
||||||
runs-on: ubuntu-latest
|
runs-on: Ubuntu-20.04
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
|
|
|
@ -96,7 +96,7 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa
|
||||||
$dateIntervalFormat = substr($dateIntervalFormat, 2);
|
$dateIntervalFormat = substr($dateIntervalFormat, 2);
|
||||||
break;
|
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)) {
|
if (!preg_match($valuePattern, $data)) {
|
||||||
throw new UnexpectedValueException(sprintf('Value "%s" contains intervals not accepted by format "%s".', $data, $dateIntervalFormat));
|
throw new UnexpectedValueException(sprintf('Value "%s" contains intervals not accepted by format "%s".', $data, $dateIntervalFormat));
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,14 @@ class DateIntervalNormalizerTest extends TestCase
|
||||||
$this->assertDateIntervalEquals($this->getInterval($output), $normalizer->denormalize($input, \DateInterval::class));
|
$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()
|
public function testDenormalizeExpectsString()
|
||||||
{
|
{
|
||||||
$this->expectException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
Reference in New Issue