Skip to content

Commit

Permalink
1979-add-date-function-aliases-to-parser
Browse files Browse the repository at this point in the history
- Extend unit test with non existing interval
- DAYOFYEAR is alias for DAY
  • Loading branch information
paulrutter committed Oct 22, 2024
1 parent 620426d commit 51bf815
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/alasqlparser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ COLUMNS return 'COLUMN'
DATABASE(S)? return 'DATABASE'
'DAY' return 'DAY'
'DAYOFMONTH' return 'DAY'
'DAYOFYEAR' return 'DAYOFYEAR'
'DAYOFYEAR' return 'DAY'
'DATEADD' return 'DATEADD'
'DATEDIFF' return 'DATEDIFF'
'DAYOFWEEK' return 'DAYOFWEEK'
Expand Down
2 changes: 1 addition & 1 deletion src/alasqlparser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion test/test1979.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,22 @@ describe('Test ' + test + ' - date function aliases in the parser', function ()
assert.throws(function() {
alasql('SELECT DAYOFWEEK(NOW()) AS DAYOFWEEK');
});
assert.throws(function() {
alasql('SELECT DAYOFMONTH(NOW()) AS DAYOFMONTH');
});
assert.throws(function() {
alasql('SELECT MONTH(NOW()) AS MONTH');
});
assert.throws(function() {
alasql('SELECT YEAR(NOW()) AS YEAR');
});

// As literal is fine
alasql("SELECT SECOND(NOW()) AS 'SECOND'");
alasql("SELECT HOUR(NOW()) AS 'HOUR'");
alasql("SELECT MINUTE(NOW()) AS 'MINUTE'");
alasql("SELECT DAY(NOW()) AS 'DAY'");
alasql("SELECT DAYOFWEEK(NOW()) AS 'DAYOFWEEK'");
alasql("SELECT DAYOFMONTH(NOW()) AS 'DAYOFMONTH'");
alasql("SELECT MONTH(NOW()) AS 'MONTH'");
alasql("SELECT YEAR(NOW()) AS 'YEAR'");
});
Expand Down Expand Up @@ -120,5 +123,13 @@ describe('Test ' + test + ' - date function aliases in the parser', function ()
// Verify it subtracted 10 days from 20081012
assert.equal(2, alasql('SELECT DATE_SUB(DATE("20081012"), INTERVAL 10 DAY) AS a')[0].a.getDate());
assert.equal(2, alasql('SELECT SUBDATE(DATE("20081012"), INTERVAL 10 DAY) AS a')[0].a.getDate());

// Assert DAYOFYEAR
assert.equal(107, alasql('SELECT SUBDATE(DATE("20080101"), INTERVAL 10 DAYOFYEAR) AS a')[0].a.getYear());

// Assert that nonexistinginterval throws
assert.throws(function() {
alasql('SELECT ADDDATE(DATE("20081012"), INTERVAL 10 nonexistinginterval) AS a');
});
});
});

0 comments on commit 51bf815

Please sign in to comment.