Unverified Commit f62711ae authored by Sergei Morozov's avatar Sergei Morozov

Merge branch 'fix/#3093-dateinterval-legacy-format' into 2.7

parents 2cc12a17 46fab669
...@@ -56,10 +56,17 @@ class DateIntervalType extends Type ...@@ -56,10 +56,17 @@ class DateIntervalType extends Type
return $value; return $value;
} }
$negative = false;
if (isset($value[0]) && ($value[0] === '+' || $value[0] === '-')) {
$negative = $value[0] === '-';
$value = substr($value, 1);
}
try { try {
$interval = new \DateInterval(substr($value, 1)); $interval = new \DateInterval($value);
if (substr($value, 0, 1) === '-') { if ($negative) {
$interval->invert = 1; $interval->invert = 1;
} }
......
...@@ -67,6 +67,14 @@ final class DateIntervalTest extends DbalTestCase ...@@ -67,6 +67,14 @@ final class DateIntervalTest extends DbalTestCase
self::assertEquals('-P02Y00M01DT01H02M03S', $interval->format(DateIntervalType::FORMAT)); 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 public function testInvalidDateIntervalFormatConversion() : void
{ {
$this->expectException(ConversionException::class); $this->expectException(ConversionException::class);
...@@ -79,6 +87,13 @@ final class DateIntervalTest extends DbalTestCase ...@@ -79,6 +87,13 @@ final class DateIntervalTest extends DbalTestCase
self::assertNull($this->type->convertToPHPValue(null, $this->platform)); self::assertNull($this->type->convertToPHPValue(null, $this->platform));
} }
public function testDateIntervalEmptyStringConversion() : void
{
$this->expectException(ConversionException::class);
$this->type->convertToPHPValue('', $this->platform);
}
/** /**
* @group DBAL-1288 * @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