fix date interval storage

This commit is contained in:
Julien Fastré 2018-05-04 10:40:38 +02:00
parent 395787f1bb
commit 5693091591

View File

@ -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) {