Commit 6c867a0f authored by Marco Pivetta's avatar Marco Pivetta

#869 - DBAL-1293 - `DateIntervalType` should throw on invalid types

parent ae67ace8
...@@ -33,20 +33,17 @@ class DateIntervalType extends Type ...@@ -33,20 +33,17 @@ class DateIntervalType extends Type
*/ */
public function convertToDatabaseValue($value, AbstractPlatform $platform) public function convertToDatabaseValue($value, AbstractPlatform $platform)
{ {
$spec = null; if (null === $value) {
if ($value !== null) { return null;
/** @var \DateInterval $value */ }
$spec = 'P'
if ($value instanceof \DateInterval) {
return 'P'
. str_pad($value->y, 4, '0', STR_PAD_LEFT) . '-' . str_pad($value->y, 4, '0', STR_PAD_LEFT) . '-'
. $value->format('%M') . '-' . $value->format('%M-%DT%H:%I:%S');
. $value->format('%D') . 'T'
. $value->format('%H') . ':'
. $value->format('%I') . ':'
. $value->format('%S')
;
} }
return $spec; throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateInterval']);
} }
/** /**
......
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