diff --git a/hana/lib/cql-functions.js b/hana/lib/cql-functions.js index 0f7aa005e..52f758ce1 100644 --- a/hana/lib/cql-functions.js +++ b/hana/lib/cql-functions.js @@ -107,6 +107,7 @@ const StandardFunctions = { current_date: () => 'current_utcdate', current_time: () => 'current_utctime', current_timestamp: () => 'current_utctimestamp', + current_utctimestamp: x => x ? `current_utctimestamp(${x})` : 'current_utctimestamp', fractionalseconds: x => `(TO_DECIMAL(SECOND(${x}),5,3) - TO_INTEGER(SECOND(${x})))`, } diff --git a/hana/test/hana-functions.test.js b/hana/test/hana-functions.test.js new file mode 100644 index 000000000..b9f8bd4df --- /dev/null +++ b/hana/test/hana-functions.test.js @@ -0,0 +1,50 @@ +const cds = require('../../test/cds') + +describe('HANA native functions', () => { + const { expect } = cds.test(__dirname, 'fuzzy.cds') + + describe('current_timestamp', () => { + test('no arguments', async () => { + const cqn = { SELECT: { + one: true, + from: {ref: ['DUMMY']}, + columns: [{func: 'current_utctimestamp', as: 'NO'}] + }} + + const res = await cds.run(cqn) + + expect(res.NO.match(/\.(\d\d\d)0000/)).not.to.be.null // default 3 + }) + + // HXE does not allow args + test.skip('0 skips ms precision', async () => { + const cqn = { SELECT: { + one: true, + from: {ref: ['DUMMY']}, + columns: [ + {func: 'current_utctimestamp', as: 'NO'}, + {func: 'current_utctimestamp', args: [{val: 0}], as: 'P0'}] + }} + + const res = await cds.run(cqn) + + expect(res.P0.match(/\.0000000/)).not.to.be.null + }) + + // HXE does not allow args + test.skip('arbitrary values', async () => { + const cqn = { SELECT: { + one: true, + from: {ref: ['DUMMY']}, + columns: [ + {func: 'current_utctimestamp', args: [{val: 3}], as: 'P3'}, + {func: 'current_utctimestamp', args: [{val: 7}], as: 'P7'}] + }} + + const res = await cds.run(cqn) + + expect(res.P3.match(/\.(\d\d\d)0000/)).not.to.be.null + expect(res.P7.match(/\.(\d\d\d\d\d\d\d)/)).not.to.be.null + }) + }) +}) \ No newline at end of file