diff --git a/Types/DateType.php b/Types/DateType.php index 5dc9ca5..a6c92c2 100644 --- a/Types/DateType.php +++ b/Types/DateType.php @@ -1,8 +1,8 @@ + * @author Felix Nagel */ namespace Realestate\MssqlBundle\Types; @@ -13,41 +13,38 @@ use Doctrine\DBAL\Types\ConversionException; /** - * Type that maps an SQL DATE to a PHP DateTime object. + * Type that maps an SQL DATE/TIMESTAMP to a PHP DateTime object. * * @since 2.0 */ class DateType extends BaseDateType { - public function getName() - { - return Type::DATE; - } - - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) - { - return $platform->getDateTypeDeclarationSQL($fieldDeclaration); - } - - public function convertToDatabaseValue($value, AbstractPlatform $platform) - { - return ($value !== null) - ? $value->format($platform->getDateFormatString()) : null; - } - public function convertToPHPValue($value, AbstractPlatform $platform) - { + { if ($value === null) { return null; - } - - $val = \Realestate\MssqlBundle\Types\RealestateDateTime::createFromFormat('!'.$platform->getDateFormatString(), $value); + } - if (!$val) { - throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateFormatString()); + if ($value === "") { + return null; } - return $val; - } + $val = \DateTime::createFromFormat('Y-m-d', $value); + if (!$val) { + throw ConversionException::conversionFailedFormat($value, $this->getName(), 'Y-m-d'); + } -} + return $val; + } + + /** + * + * @param DateTime $value + * @param AbstractPlatform $platform + * @return string|null + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + return ($value !== null) ? $value->format('Y-m-d') : null; + } +} \ No newline at end of file