@@ -29,6 +29,11 @@ public function dataProviderISO()
2929 ['P%yY%mM%dDT%hH%iM ' ,'P10Y2M3DT16H5M ' ,'P10Y2M3DT16H5M ' ],
3030 ['P%yY%mM%dDT%hH ' ,'P10Y2M3DT16H ' ,'P10Y2M3DT16H ' ],
3131 ['P%yY%mM%dD ' ,'P10Y2M3D ' ,'P10Y2M3DT0H ' ],
32+ ['%RP%yY%mM%dD ' ,'-P10Y2M3D ' ,'-P10Y2M3DT0H ' ],
33+ ['%RP%yY%mM%dD ' ,'+P10Y2M3D ' ,'+P10Y2M3DT0H ' ],
34+ ['%RP%yY%mM%dD ' ,'+P10Y2M3D ' ,'P10Y2M3DT0H ' ],
35+ ['%rP%yY%mM%dD ' ,'-P10Y2M3D ' ,'-P10Y2M3DT0H ' ],
36+ ['%rP%yY%mM%dD ' ,'P10Y2M3D ' ,'P10Y2M3DT0H ' ],
3237 ];
3338
3439return $ data ;
@@ -50,15 +55,15 @@ public function testNormalize()
5055 */
5156public function testNormalizeUsingFormatPassedInContext ($ format ,$ output ,$ input )
5257 {
53- $ this ->assertEquals ($ output ,$ this ->normalizer ->normalize (new \ DateInterval ($ input ),null , [DateIntervalNormalizer::FORMAT_KEY =>$ format ]));
58+ $ this ->assertEquals ($ output ,$ this ->normalizer ->normalize ($ this -> getInterval ($ input ),null , [DateIntervalNormalizer::FORMAT_KEY =>$ format ]));
5459 }
5560
5661/**
5762 * @dataProvider dataProviderISO
5863 */
5964public function testNormalizeUsingFormatPassedInConstructor ($ format ,$ output ,$ input )
6065 {
61- $ this ->assertEquals ($ output , (new DateIntervalNormalizer ($ format ))->normalize (new \ DateInterval ($ input )));
66+ $ this ->assertEquals ($ output , (new DateIntervalNormalizer ($ format ))->normalize ($ this -> getInterval ($ input )));
6267 }
6368
6469public function testNormalizeInvalidObjectThrowsException ()
@@ -84,15 +89,15 @@ public function testDenormalize()
8489 */
8590public function testDenormalizeUsingFormatPassedInContext ($ format ,$ input ,$ output )
8691 {
87- $ this ->assertDateIntervalEquals (new \ DateInterval ( $ output ),$ this ->normalizer ->denormalize ($ input , \DateInterval::class,null , [DateIntervalNormalizer::FORMAT_KEY =>$ format ]));
92+ $ this ->assertDateIntervalEquals ($ this -> getInterval ( $ input ),$ this ->normalizer ->denormalize ($ input , \DateInterval::class,null , [DateIntervalNormalizer::FORMAT_KEY =>$ format ]));
8893 }
8994
9095/**
9196 * @dataProvider dataProviderISO
9297 */
9398public function testDenormalizeUsingFormatPassedInConstructor ($ format ,$ input ,$ output )
9499 {
95- $ this ->assertDateIntervalEquals (new \ DateInterval ( $ output ), (new DateIntervalNormalizer ($ format ))->denormalize ($ input , \DateInterval::class));
100+ $ this ->assertDateIntervalEquals ($ this -> getInterval ( $ input ), (new DateIntervalNormalizer ($ format ))->denormalize ($ input , \DateInterval::class));
96101 }
97102
98103public function testDenormalizeExpectsString ()
@@ -124,4 +129,18 @@ private function assertDateIntervalEquals(\DateInterval $expected, \DateInterval
124129 {
125130$ this ->assertEquals ($ expected ->format ('%RP%yY%mM%dDT%hH%iM%sS ' ),$ actual ->format ('%RP%yY%mM%dDT%hH%iM%sS ' ));
126131 }
132+
133+ private function getInterval ($ data ):\DateInterval
134+ {
135+ if ($ data [0 ] ==='- ' ) {
136+ $ interval =new \DateInterval (\substr ($ data ,1 ));
137+ $ interval ->invert =1 ;
138+
139+ return $ interval ;
140+ }elseif ($ data [0 ] ==='+ ' ) {
141+ return new \DateInterval (\substr ($ data ,1 ));
142+ }else {
143+ return new \DateInterval ($ data );
144+ }
145+ }
127146}