Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c88d49e

Browse filesBrowse files
committed
[Serializer] Fix denormalizing date intervals having both weeks and days
1 parent 4d140c3 commit c88d49e
Copy full SHA for c88d49e

File tree

Expand file treeCollapse file tree

2 files changed

+19
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-0
lines changed

‎src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/DateIntervalNormalizer.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ public function supportsDenormalization($data, string $type, string $format = nu
128128

129129
private function isISO8601(string $string): bool
130130
{
131+
if (\PHP_VERSION_ID >= 80000) {
132+
return preg_match('/^[\-+]?P(?=\w*(?:\d|%\w))(?:\d+Y|%[yY]Y)?(?:\d+M|%[mM]M)?(?:\d+W|%[wW]W)?(?:\d+D|%[dD]D)?(?:T(?:\d+H|[hH]H)?(?:\d+M|[iI]M)?(?:\d+S|[sS]S)?)?$/', $string);
133+
}
134+
131135
return preg_match('/^[\-+]?P(?=\w*(?:\d|%\w))(?:\d+Y|%[yY]Y)?(?:\d+M|%[mM]M)?(?:(?:\d+D|%[dD]D)|(?:\d+W|%[wW]W))?(?:T(?:\d+H|[hH]H)?(?:\d+M|[iI]M)?(?:\d+S|[sS]S)?)?$/', $string);
132136
}
133137
}

‎src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/DateIntervalNormalizerTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ public function testDenormalizeIntervalsWithOmittedPartsBeingZero()
119119
$this->assertDateIntervalEquals($this->getInterval('P0Y0M0DT12H34M0S'), $normalizer->denormalize('PT12H34M', \DateInterval::class));
120120
}
121121

122+
/**
123+
* Since PHP 8.0 DateInterval::construct supports periods containing both D and W period designators.
124+
*
125+
* @requires PHP 8
126+
*/
127+
public function testDenormalizeIntervalWithBothWeeksAndDays()
128+
{
129+
$input = 'P1W1D';
130+
$interval = $this->normalizer->denormalize($input, \DateInterval::class, null, [
131+
DateIntervalNormalizer::FORMAT_KEY => '%rP%yY%mM%wW%dDT%hH%iM%sS',
132+
]);
133+
$this->assertDateIntervalEquals($this->getInterval($input), $interval);
134+
$this->assertSame(8, $interval->d);
135+
}
136+
122137
public function testDenormalizeExpectsString()
123138
{
124139
$this->expectException(NotNormalizableValueException::class);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.