Commit 104f97e6 authored by Benjamin Eberlei's avatar Benjamin Eberlei

[DBAL-216] Add support for Date types to also handle already instantiated DateTime instances.

parent a62df738
......@@ -46,8 +46,8 @@ class DateTimeType extends Type
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
if ($value === null || $value instanceof \DateTime) {
return $value;
}
$val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value);
......@@ -56,4 +56,4 @@ class DateTimeType extends Type
}
return $val;
}
}
\ No newline at end of file
}
......@@ -66,8 +66,8 @@ class DateTimeTzType extends Type
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
if ($value === null || $value instanceof \DateTime) {
return $value;
}
$val = \DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value);
......@@ -76,4 +76,4 @@ class DateTimeTzType extends Type
}
return $val;
}
}
\ No newline at end of file
}
......@@ -46,8 +46,8 @@ class DateType extends Type
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
if ($value === null || $value instanceof \DateTime) {
return $value;
}
$val = \DateTime::createFromFormat('!'.$platform->getDateFormatString(), $value);
......@@ -56,4 +56,4 @@ class DateType extends Type
}
return $val;
}
}
\ No newline at end of file
}
......@@ -55,8 +55,8 @@ class TimeType extends Type
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
if ($value === null || $value instanceof \DateTime) {
return $value;
}
$val = \DateTime::createFromFormat($platform->getTimeFormatString(), $value);
......@@ -65,4 +65,4 @@ class TimeType extends Type
}
return $val;
}
}
\ No newline at end of file
}
......@@ -47,8 +47,8 @@ class VarDateTimeType extends DateTimeType
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null) {
return null;
if ($value === null || $value instanceof \DateTime) {
return $value;
}
$val = date_create($value);
......@@ -57,4 +57,4 @@ class VarDateTimeType extends DateTimeType
}
return $val;
}
}
\ No newline at end of file
}
......@@ -72,4 +72,10 @@ class DateTest extends \Doctrine\Tests\DbalTestCase
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
\ No newline at end of file
public function testConvertDateTimeToPHPValue()
{
$date = new \DateTime("now");
$this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform));
}
}
......@@ -47,4 +47,10 @@ class DateTimeTest extends \Doctrine\Tests\DbalTestCase
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
\ No newline at end of file
public function testConvertDateTimeToPHPValue()
{
$date = new \DateTime("now");
$this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform));
}
}
......@@ -47,4 +47,10 @@ class DateTimeTzTest extends \Doctrine\Tests\DbalTestCase
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
\ No newline at end of file
public function testConvertDateTimeToPHPValue()
{
$date = new \DateTime("now");
$this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform));
}
}
......@@ -44,4 +44,10 @@ class TimeTest extends \Doctrine\Tests\DbalTestCase
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
\ No newline at end of file
public function testConvertDateTimeToPHPValue()
{
$date = new \DateTime("now");
$this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform));
}
}
......@@ -59,4 +59,10 @@ class VarDateTimeTest extends \Doctrine\Tests\DbalTestCase
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
\ No newline at end of file
public function testConvertDateTimeToPHPValue()
{
$date = new \DateTime("now");
$this->assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform));
}
}
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