1
0
mirror of synced 2025-01-22 08:11:40 +03:00

Add hour to DATE_ADD and DATE_SUB

This commit is contained in:
amakhov 2013-08-06 12:20:22 +04:00
parent 97762d21a4
commit dd975fe53d
2 changed files with 11 additions and 1 deletions

View File

@ -45,6 +45,11 @@ class DateAddFunction extends FunctionNode
public function getSql(SqlWalker $sqlWalker) public function getSql(SqlWalker $sqlWalker)
{ {
switch (strtolower($this->unit->value)) { switch (strtolower($this->unit->value)) {
case 'hour':
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddHourExpression(
$this->firstDateExpression->dispatch($sqlWalker),
$this->intervalExpression->dispatch($sqlWalker)
);
case 'day': case 'day':
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddDaysExpression( return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddDaysExpression(
$this->firstDateExpression->dispatch($sqlWalker), $this->firstDateExpression->dispatch($sqlWalker),
@ -59,7 +64,7 @@ class DateAddFunction extends FunctionNode
default: default:
throw QueryException::semanticalError( throw QueryException::semanticalError(
'DATE_ADD() only supports units of type day and month.' 'DATE_ADD() only supports units of type hour, day and month.'
); );
} }
} }

View File

@ -39,6 +39,11 @@ class DateSubFunction extends DateAddFunction
public function getSql(SqlWalker $sqlWalker) public function getSql(SqlWalker $sqlWalker)
{ {
switch (strtolower($this->unit->value)) { switch (strtolower($this->unit->value)) {
case 'hour':
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubHourExpression(
$this->firstDateExpression->dispatch($sqlWalker),
$this->intervalExpression->dispatch($sqlWalker)
);
case 'day': case 'day':
return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubDaysExpression( return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubDaysExpression(
$this->firstDateExpression->dispatch($sqlWalker), $this->firstDateExpression->dispatch($sqlWalker),