DATE_ADD - Support for seconds
This commit is contained in:
parent
1369cdda2b
commit
57bcd7cd3d
@ -45,6 +45,12 @@ class DateAddFunction extends FunctionNode
|
||||
public function getSql(SqlWalker $sqlWalker)
|
||||
{
|
||||
switch (strtolower($this->unit->value)) {
|
||||
case 'second':
|
||||
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddSecondsExpression(
|
||||
$this->firstDateExpression->dispatch($sqlWalker),
|
||||
$this->intervalExpression->dispatch($sqlWalker)
|
||||
);
|
||||
|
||||
case 'hour':
|
||||
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddHourExpression(
|
||||
$this->firstDateExpression->dispatch($sqlWalker),
|
||||
@ -64,7 +70,7 @@ class DateAddFunction extends FunctionNode
|
||||
|
||||
default:
|
||||
throw QueryException::semanticalError(
|
||||
'DATE_ADD() only supports units of type hour, day and month.'
|
||||
'DATE_ADD() only supports units of type second, hour, day and month.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -300,6 +300,23 @@ class QueryDqlFunctionTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertTrue(strtotime($arg[0]['add']) > 0);
|
||||
}
|
||||
|
||||
public function testDateAddSecond()
|
||||
{
|
||||
$dql = "SELECT CURRENT_TIMESTAMP() now, DATE_ADD(CURRENT_TIMESTAMP(), 10, 'second') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m";
|
||||
$query = $this->_em->createQuery($dql)->setMaxResults(1);
|
||||
$result = $query->getArrayResult();
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertArrayHasKey('now', $result[0]);
|
||||
$this->assertArrayHasKey('add', $result[0]);
|
||||
|
||||
$now = strtotime($result[0]['now']);
|
||||
$add = strtotime($result[0]['add']);
|
||||
$diff = $add - $now;
|
||||
|
||||
$this->assertSQLEquals(10, $diff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1014
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user