diff --git a/Doctrine/Type/NativeDateIntervalType.php b/Doctrine/Type/NativeDateIntervalType.php index 7c9375628..12e8b789b 100644 --- a/Doctrine/Type/NativeDateIntervalType.php +++ b/Doctrine/Type/NativeDateIntervalType.php @@ -14,6 +14,7 @@ use Doctrine\DBAL\Types\ConversionException; */ class NativeDateIntervalType extends DateIntervalType { + const FORMAT = '%rP%YY%MM%DDT%HH%IM%SS'; public function getName(): string { @@ -25,6 +26,22 @@ class NativeDateIntervalType extends DateIntervalType return 'INTERVAL'; } + /** + * {@inheritdoc} + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + if (null === $value) { + return null; + } + + if ($value instanceof \DateInterval) { + return $value->format(self::FORMAT); + } + + throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateInterval']); + } + public function convertToPHPValue($value, AbstractPlatform $platform) { if ($value === null || $value instanceof \DateInterval) {