-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luatiq
committed
Apr 4, 2024
1 parent
0f77e47
commit 5faec51
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace DoctrineExtensions\Query\Mysql; | ||
|
||
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | ||
use Doctrine\ORM\Query\Parser; | ||
use Doctrine\ORM\Query\SqlWalker; | ||
use Doctrine\ORM\Query\TokenType; | ||
|
||
class SubTime extends FunctionNode | ||
{ | ||
public $date; | ||
|
||
public $time; | ||
|
||
public function getSql(SqlWalker $sqlWalker): string | ||
{ | ||
return 'SUBTIME(' . $sqlWalker->walkArithmeticPrimary($this->date) . ', ' . $sqlWalker->walkArithmeticPrimary($this->time) . ')'; | ||
} | ||
|
||
public function parse(Parser $parser): void | ||
{ | ||
$parser->match(TokenType::T_IDENTIFIER); | ||
$parser->match(TokenType::T_OPEN_PARENTHESIS); | ||
|
||
$this->date = $parser->ArithmeticPrimary(); | ||
|
||
$parser->match(TokenType::T_COMMA); | ||
|
||
$this->time = $parser->ArithmeticPrimary(); | ||
|
||
$parser->match(TokenType::T_CLOSE_PARENTHESIS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace DoctrineExtensions\Tests\Query\Mysql; | ||
|
||
use DoctrineExtensions\Tests\Query\MysqlTestCase; | ||
|
||
class SubTimeTest extends MysqlTestCase | ||
{ | ||
public function testSubTime(): void | ||
{ | ||
$this->assertDqlProducesSql( | ||
"SELECT SUBTIME('2024-04-04 19:35:00','01:22:33') from DoctrineExtensions\Tests\Entities\Blank b", | ||
"SELECT SUBTIME('2024-04-04 19:35:00', '01:22:33') AS sclr_0 FROM Blank b0_" | ||
); | ||
} | ||
} |