Skip to content

Commit

Permalink
Merge pull request #6348 from cakephp/master-fix-datetime
Browse files Browse the repository at this point in the history
Allow BC for nullish DB values as strings.
  • Loading branch information
markstory committed Apr 16, 2015
2 parents cc7ebbb + 960d3df commit d58cfbb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Database/Type/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function toDatabase($value, Driver $driver)
*/
public function toPHP($value, Driver $driver)
{
if ($value === null) {
if ($value === null || (int)$value === 0) {
return null;
}

Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Database/Type/DateTimeTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function tearDown()
public function testToPHP()
{
$this->assertNull($this->type->toPHP(null, $this->driver));
$this->assertNull($this->type->toPHP('0000-00-00 00:00:00', $this->driver));

$result = $this->type->toPHP('2001-01-04 12:13:14', $this->driver);
$this->assertInstanceOf('Cake\I18n\Time', $result);
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Database/Type/DateTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function setUp()
public function testToPHP()
{
$this->assertNull($this->type->toPHP(null, $this->driver));
$this->assertNull($this->type->toPHP('0000-00-00', $this->driver));

$result = $this->type->toPHP('2001-01-04', $this->driver);
$this->assertInstanceOf('DateTime', $result);
Expand Down

0 comments on commit d58cfbb

Please sign in to comment.