Skip to content

Commit

Permalink
DBAL-26 - Fix nasty bug with null values in Date, DateTime, DateTimeT…
Browse files Browse the repository at this point in the history
…z and Time fields introduced with the DBAL-22 fix
  • Loading branch information
beberlei committed Jun 27, 2010
1 parent 1442262 commit bb2ffc4
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 8 deletions.
7 changes: 5 additions & 2 deletions lib/Doctrine/DBAL/Types/DateTimeType.php
Expand Up @@ -46,8 +46,11 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)

public function convertToPHPValue($value, AbstractPlatform $platform)
{
$val = ($value !== null)
? \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value) : null;
if (!$value) {
return $value;
}

$val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName());
}
Expand Down
7 changes: 5 additions & 2 deletions lib/Doctrine/DBAL/Types/DateTimeTzType.php
Expand Up @@ -66,8 +66,11 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)

public function convertToPHPValue($value, AbstractPlatform $platform)
{
$val = ($value !== null)
? \DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value) : null;
if (!$value) {
return $value;
}

$val = \DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName());
}
Expand Down
7 changes: 5 additions & 2 deletions lib/Doctrine/DBAL/Types/DateType.php
Expand Up @@ -46,8 +46,11 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)

public function convertToPHPValue($value, AbstractPlatform $platform)
{
$val = ($value !== null)
? \DateTime::createFromFormat('!'.$platform->getDateFormatString(), $value) : null;
if (!$value) {
return $value;
}

$val = \DateTime::createFromFormat('!'.$platform->getDateFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName());
}
Expand Down
7 changes: 5 additions & 2 deletions lib/Doctrine/DBAL/Types/TimeType.php
Expand Up @@ -55,8 +55,11 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
$val = ($value !== null)
? \DateTime::createFromFormat($platform->getTimeFormatString(), $value) : null;
if (!$value) {
return $value;
}

$val = \DateTime::createFromFormat($platform->getTimeFormatString(), $value);
if (!$val) {
throw ConversionException::conversionFailed($value, $this->getName());
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Doctrine/Tests/DBAL/Types/DateTest.php
Expand Up @@ -67,4 +67,9 @@ public function testInvalidDateFormatConversion()
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->_type->convertToPHPValue('abcdefg', $this->_platform);
}

public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
5 changes: 5 additions & 0 deletions tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php
Expand Up @@ -42,4 +42,9 @@ public function testInvalidDateTimeFormatConversion()
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->_type->convertToPHPValue('abcdefg', $this->_platform);
}

public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
5 changes: 5 additions & 0 deletions tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php
Expand Up @@ -42,4 +42,9 @@ public function testInvalidDateFormatConversion()
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->_type->convertToPHPValue('abcdefg', $this->_platform);
}

public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
5 changes: 5 additions & 0 deletions tests/Doctrine/Tests/DBAL/Types/TimeTest.php
Expand Up @@ -39,4 +39,9 @@ public function testInvalidTimeFormatConversion()
$this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
$this->_type->convertToPHPValue('abcdefg', $this->_platform);
}

public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}

0 comments on commit bb2ffc4

Please sign in to comment.