diff -urN ./DoctrineORM-2.2.2/Doctrine/DBAL/Platforms/AbstractPlatform.php ./Doctrine/DBAL/Platforms/AbstractPlatform.php --- ./DoctrineORM-2.2.2/Doctrine/DBAL/Platforms/AbstractPlatform.php 2012-04-13 10:24:58.000000000 +0200 +++ ./Doctrine/DBAL/Platforms/AbstractPlatform.php 2012-11-16 09:36:37.000000000 +0100 @@ -2226,6 +2226,11 @@ throw DBALException::notSupported(__METHOD__); } + public function getTimestampTypeDeclarationSQL(array $fieldDeclaration) + { + return "TIMESTAMP"; + } + public function getFloatDeclarationSQL(array $fieldDeclaration) { return 'DOUBLE PRECISION'; @@ -2455,6 +2460,9 @@ return 'H:i:s'; } + public function getTimestampFormatString() { + return 'Y-m-d H:i:s'; + } /** * Modify limit query * diff -urN ./DoctrineORM-2.2.2/Doctrine/DBAL/Types/TimestampType.php ./Doctrine/DBAL/Types/TimestampType.php --- ./DoctrineORM-2.2.2/Doctrine/DBAL/Types/TimestampType.php 1970-01-01 01:00:00.000000000 +0100 +++ ./Doctrine/DBAL/Types/TimestampType.php 2012-11-16 09:36:15.000000000 +0100 @@ -0,0 +1,68 @@ +. + */ + +namespace Doctrine\DBAL\Types; + +use Doctrine\DBAL\Platforms\AbstractPlatform; + +/** + * Type that maps an SQL TIME to a PHP DateTime object. + * + * @since 2.0 + */ +class TimestampType extends Type +{ + public function getName() + { + return Type::TIMESTAMP; + } + + /** + * {@inheritdoc} + */ + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + { + return $platform->getTimestampTypeDeclarationSQL($fieldDeclaration); + } + + /** + * {@inheritdoc} + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + return ($value !== null) + ? $value->format($platform->getTimestampFormatString()) : null; + } + + /** + * {@inheritdoc} + */ + public function convertToPHPValue($value, AbstractPlatform $platform) + { + if ($value === null) { + return null; + } + + $val = \DateTime::createFromFormat($platform->getTimestampFormatString(), $value); + if (!$val) { + throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimestampFormatString()); + } + return $val; + } +} \ No newline at end of file diff -urN ./DoctrineORM-2.2.2/Doctrine/DBAL/Types/Type.php ./Doctrine/DBAL/Types/Type.php --- ./DoctrineORM-2.2.2/Doctrine/DBAL/Types/Type.php 2012-04-13 10:24:58.000000000 +0200 +++ ./Doctrine/DBAL/Types/Type.php 2012-11-16 09:33:58.000000000 +0100 @@ -48,6 +48,7 @@ const TEXT = 'text'; const BLOB = 'blob'; const FLOAT = 'float'; + const TIMESTAMP = 'timestamp'; /** Map of already instantiated type objects. One instance per type (flyweight). */ private static $_typeObjects = array(); @@ -69,6 +70,7 @@ self::DECIMAL => 'Doctrine\DBAL\Types\DecimalType', self::FLOAT => 'Doctrine\DBAL\Types\FloatType', self::BLOB => 'Doctrine\DBAL\Types\BlobType', + self::TIMESTAMP => 'Doctrine\DBAL\Types\TimestampType', ); /* Prevent instantiation and force use of the factory method. */