|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import dayjs from 'dayjs'; |
|
|
|
|
import { MapFnArgs } from '../mapFunctionName'; |
|
|
|
|
import commonFns from './commonFns'; |
|
|
|
|
import { convertUnits } from '../helpers/convertUnits'; |
|
|
|
|
import { getWeekdayByText } from '../helpers/formulaFnHelper'; |
|
|
|
|
|
|
|
|
|
const mssql = { |
|
|
|
@ -110,6 +111,17 @@ const mssql = {
|
|
|
|
|
END${colAlias}` |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
DATETIME_DIFF: ({ fn, knex, pt, colAlias }: MapFnArgs) => { |
|
|
|
|
const datetime_expr1 = fn(pt.arguments[0]); |
|
|
|
|
const datetime_expr2 = fn(pt.arguments[1]); |
|
|
|
|
const rawUnit = pt.arguments[2] |
|
|
|
|
? fn(pt.arguments[2]).bindings[0] |
|
|
|
|
: 'seconds'; |
|
|
|
|
const unit = convertUnits(rawUnit, 'mssql'); |
|
|
|
|
return knex.raw( |
|
|
|
|
`DATEDIFF(${unit}, ${datetime_expr2}, ${datetime_expr1}) ${colAlias}` |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
WEEKDAY: ({ fn, knex, pt, colAlias }: MapFnArgs) => { |
|
|
|
|
// DATEPART(WEEKDAY, DATE): sunday = 1, monday = 2, ..., saturday = 7
|
|
|
|
|
// WEEKDAY() returns an index from 0 to 6 for Monday to Sunday
|
|
|
|
|