Unverified Commit f2d1f378 authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #3097 from Majkl578/fix/#3093-dateinterval-legacy-format

Fix compatibility for pre-2.7 DateIntervalType format
parents d4a96deb 0aa75d84
......@@ -56,10 +56,17 @@ class DateIntervalType extends Type
return $value;
}
$negative = false;
if (isset($value[0]) && ($value[0] === '+' || $value[0] === '-')) {
$negative = $value[0] === '-';
$value = substr($value, 1);
}
try {
$interval = new \DateInterval(substr($value, 1));
$interval = new \DateInterval($value);
if (substr($value, 0, 1) === '-') {
if ($negative) {
$interval->invert = 1;
}
......
......@@ -67,6 +67,14 @@ final class DateIntervalTest extends DbalTestCase
self::assertEquals('-P02Y00M01DT01H02M03S', $interval->format(DateIntervalType::FORMAT));
}
public function testDateIntervalFormatWithoutSignConvertsToPHPValue() : void
{
$interval = $this->type->convertToPHPValue('P02Y00M01DT01H02M03S', $this->platform);
self::assertInstanceOf(\DateInterval::class, $interval);
self::assertEquals('+P02Y00M01DT01H02M03S', $interval->format(DateIntervalType::FORMAT));
}
public function testInvalidDateIntervalFormatConversion() : void
{
$this->expectException(ConversionException::class);
......@@ -79,6 +87,13 @@ final class DateIntervalTest extends DbalTestCase
self::assertNull($this->type->convertToPHPValue(null, $this->platform));
}
public function testDateIntervalEmptyStringConversion() : void
{
$this->expectException(ConversionException::class);
$this->type->convertToPHPValue('', $this->platform);
}
/**
* @group DBAL-1288
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment