From dd975fe53d7b46959abbc3951a1e84e0e55485a7 Mon Sep 17 00:00:00 2001 From: amakhov Date: Tue, 6 Aug 2013 12:20:22 +0400 Subject: [PATCH 1/2] Add hour to DATE_ADD and DATE_SUB --- lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php | 7 ++++++- lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php index 1c3817fe2a9..d78cd976aab 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/DateAddFunction.php @@ -45,6 +45,11 @@ class DateAddFunction extends FunctionNode public function getSql(SqlWalker $sqlWalker) { switch (strtolower($this->unit->value)) { + case 'hour': + return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddHourExpression( + $this->firstDateExpression->dispatch($sqlWalker), + $this->intervalExpression->dispatch($sqlWalker) + ); case 'day': return $sqlWalker->getConnection()->getDatabasePlatform()->getDateAddDaysExpression( $this->firstDateExpression->dispatch($sqlWalker), @@ -59,7 +64,7 @@ public function getSql(SqlWalker $sqlWalker) default: throw QueryException::semanticalError( - 'DATE_ADD() only supports units of type day and month.' + 'DATE_ADD() only supports units of type hour, day and month.' ); } } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php index 35add0ed699..bcd994ba9e7 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php @@ -39,6 +39,11 @@ class DateSubFunction extends DateAddFunction public function getSql(SqlWalker $sqlWalker) { switch (strtolower($this->unit->value)) { + case 'hour': + return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubHourExpression( + $this->firstDateExpression->dispatch($sqlWalker), + $this->intervalExpression->dispatch($sqlWalker) + ); case 'day': return $sqlWalker->getConnection()->getDatabasePlatform()->getDateSubDaysExpression( $this->firstDateExpression->dispatch($sqlWalker), From d8fcdc0c547df9c5ab091f21aade3cdc1ae3a963 Mon Sep 17 00:00:00 2001 From: amakhov Date: Tue, 6 Aug 2013 12:40:30 +0400 Subject: [PATCH 2/2] Add hour to DATE_ADD and DATE_SUB. Excepcion message fix --- lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php index bcd994ba9e7..d0e890fa793 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/DateSubFunction.php @@ -58,7 +58,7 @@ public function getSql(SqlWalker $sqlWalker) default: throw QueryException::semanticalError( - 'DATE_SUB() only supports units of type day and month.' + 'DATE_SUB() only supports units of type hour, day and month.' ); } }