Commit 9f72045a authored by Marco Pivetta's avatar Marco Pivetta

#869 - DBAL-1293 - simplified conversion logic for readability

parent bd142a58
......@@ -49,12 +49,15 @@ class DateTimeType extends Type
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if ($value !== null && !$value instanceof \DateTime) {
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), "DateTime");
if (null === $value) {
return $value;
}
if ($value instanceof \DateTime) {
return $value->format($platform->getDateTimeFormatString());
}
return ($value !== null)
? $value->format($platform->getDateTimeFormatString()) : null;
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), 'DateTime');
}
/**
......
......@@ -67,12 +67,15 @@ class DateTimeTzType extends Type
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if ($value !== null && !$value instanceof \DateTime) {
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), "DateTime");
if (null === $value) {
return $value;
}
if ($value instanceof \DateTime) {
return $value->format($platform->getDateTimeTzFormatString());
}
return ($value !== null)
? $value->format($platform->getDateTimeTzFormatString()) : null;
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), 'DateTime');
}
/**
......
......@@ -49,12 +49,15 @@ class DateType extends Type
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if ($value !== null && !$value instanceof \DateTime) {
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), "DateTime");
if (null === $value) {
return $value;
}
if ($value instanceof \DateTime) {
return $value->format($platform->getDateFormatString());
}
return ($value !== null)
? $value->format($platform->getDateFormatString()) : null;
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), 'DateTime');
}
/**
......
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