From 569309159192735dc30424efe7ed3531b3b8b8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 4 May 2018 10:40:38 +0200 Subject: [PATCH] fix date interval storage --- Doctrine/Type/NativeDateIntervalType.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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) {