Unverified Commit 46fab669 authored by Michael Moravec's avatar Michael Moravec Committed by Sergei Morozov

Fix compatibility for pre-2.7 DateIntervalType format

parent 2cc12a17
......@@ -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