Skip to content

Commit a8747a2

Browse files
Tigerman55stevelacey
authored andcommitted
Add makedate extension
1 parent b43949e commit a8747a2

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ MySQL, Oracle, PostgreSQL and SQLite.
1313

1414
| DB | Functions |
1515
|:--:|:---------:|
16-
| MySQL | `ACOS, ADDTIME, AES_DECRYPT, AES_ENCRYPT, ANY_VALUE, ASCII, ASIN, ATAN, ATAN2, BINARY, BIT_COUNT, BIT_XOR, CAST, CEIL, CHAR_LENGTH, COLLATE, CONCAT_WS, CONVERT_TZ, COS, COT, COUNTIF, CRC32, DATE, DATE_FORMAT, DATEADD, DATEDIFF, DATESUB, DAY, DAYNAME, DAYOFWEEK, DAYOFYEAR, DEGREES, DIV, EXP, EXTRACT, FIELD, FIND_IN_SET, FLOOR, FORMAT, FROM_UNIXTIME, GREATEST, GROUP_CONCAT, HEX, HOUR, IFELSE, IFNULL, INET_ATON, INET_NTOA, INET6_ATON, INET6_NTOA, INSTR, IS_IPV4, IS_IPV4_COMPAT, IS_IPV4_MAPPED, IS_IPV6, LAST_DAY, LEAST, LOG, LOG10, LOG2, LPAD, MATCH, MD5, MINUTE, MONTH, MONTHNAME, NOW, NULLIF, PERIOD_DIFF, PI, POWER, QUARTER, RADIANS, RAND, REGEXP, REPLACE, ROUND, RPAD, SECOND, SECTOTIME, SHA1, SHA2, SIN, SOUNDEX, STD, STDDEV, STRTODATE, STR_TO_DATE, SUBSTRING_INDEX, TAN, TIME, TIMEDIFF, TIMESTAMPADD, TIMESTAMPDIFF, TIMETOSEC, UNHEX, UNIX_TIMESTAMP, UTC_TIMESTAMP, UUID_SHORT, VARIANCE, WEEK, WEEKDAY, YEAR, YEARMONTH, YEARWEEK` |
16+
| MySQL | `ACOS, ADDTIME, AES_DECRYPT, AES_ENCRYPT, ANY_VALUE, ASCII, ASIN, ATAN, ATAN2, BINARY, BIT_COUNT, BIT_XOR, CAST, CEIL, CHAR_LENGTH, COLLATE, CONCAT_WS, CONVERT_TZ, COS, COT, COUNTIF, CRC32, DATE, DATE_FORMAT, DATEADD, DATEDIFF, DATESUB, DAY, DAYNAME, DAYOFWEEK, DAYOFYEAR, DEGREES, DIV, EXP, EXTRACT, FIELD, FIND_IN_SET, FLOOR, FORMAT, FROM_UNIXTIME, GREATEST, GROUP_CONCAT, HEX, HOUR, IFELSE, IFNULL, INET_ATON, INET_NTOA, INET6_ATON, INET6_NTOA, INSTR, IS_IPV4, IS_IPV4_COMPAT, IS_IPV4_MAPPED, IS_IPV6, LAST_DAY, LEAST, LOG, LOG10, LOG2, LPAD, MAKEDATE, MATCH, MD5, MINUTE, MONTH, MONTHNAME, NOW, NULLIF, PERIOD_DIFF, PI, POWER, QUARTER, RADIANS, RAND, REGEXP, REPLACE, ROUND, RPAD, SECOND, SECTOTIME, SHA1, SHA2, SIN, SOUNDEX, STD, STDDEV, STRTODATE, STR_TO_DATE, SUBSTRING_INDEX, TAN, TIME, TIMEDIFF, TIMESTAMPADD, TIMESTAMPDIFF, TIMETOSEC, UNHEX, UNIX_TIMESTAMP, UTC_TIMESTAMP, UUID_SHORT, VARIANCE, WEEK, WEEKDAY, YEAR, YEARMONTH, YEARWEEK` |
1717
| Oracle | `DAY, LISTAGG, MONTH, NVL, TO_CHAR, TO_DATE, TRUNC, YEAR` |
1818
| Sqlite | `DATE, MINUTE, HOUR, DAY, WEEK, WEEKDAY, MONTH, YEAR, JULIANDAY, STRFTIME, DATE_FORMAT*, CASE WHEN THEN ELSE END, IFNULL, REPLACE, ROUND` |
1919
| PostgreSQL | `DATE_PART, GREATEST, LEAST, COUNT_FILTER, STRING_AGG, TO_DATE, TO_CHAR, AT_TIME_ZONE` |

config/mysql.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ doctrine:
1717
from_unixtime: DoctrineExtensions\Query\Mysql\FromUnixtime
1818
hour: DoctrineExtensions\Query\Mysql\Hour
1919
last_day: DoctrineExtensions\Query\Mysql\LastDay
20+
makedate: DoctrineExtensions\Query\Mysql\MakeDate
2021
minute: DoctrineExtensions\Query\Mysql\Minute
2122
now: DoctrineExtensions\Query\Mysql\Now
2223
month: DoctrineExtensions\Query\Mysql\Month

src/Query/Mysql/MakeDate.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace DoctrineExtensions\Query\Mysql;
4+
5+
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
6+
use Doctrine\ORM\Query\Lexer;
7+
8+
class MakeDate extends FunctionNode
9+
{
10+
public $year = null;
11+
12+
public $dayOfYear = null;
13+
14+
public function parse(\Doctrine\ORM\Query\Parser $parser)
15+
{
16+
$parser->match(Lexer::T_IDENTIFIER);
17+
$parser->match(Lexer::T_OPEN_PARENTHESIS);
18+
$this->year = $parser->ArithmeticPrimary();
19+
$parser->match(Lexer::T_COMMA);
20+
$this->dayOfYear = $parser->ArithmeticPrimary();
21+
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
22+
}
23+
24+
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
25+
{
26+
return 'MAKEDATE('.
27+
$sqlWalker->walkArithmeticPrimary($this->year).', '.
28+
$sqlWalker->walkArithmeticPrimary($this->dayOfYear).
29+
')';
30+
}
31+
}

tests/Query/Mysql/MakeDateTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace DoctrineExtensions\Tests\Query\Mysql;
4+
5+
use DoctrineExtensions\Tests\Query\MysqlTestCase;
6+
7+
class MakeDateTest extends MysqlTestCase
8+
{
9+
public function testMakeDate()
10+
{
11+
$this->assertDqlProducesSql(
12+
"SELECT MAKEDATE(2019, 5) FROM DoctrineExtensions\Tests\Entities\Blank b",
13+
'SELECT MAKEDATE(2019, 5) AS sclr_0 FROM Blank b0_'
14+
);
15+
}
16+
}

0 commit comments

Comments
 (0)