|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
import commonFns from './commonFns'; |
|
|
|
|
import { MapFnArgs } from '../mapFunctionName'; |
|
|
|
|
import dayjs from 'dayjs'; |
|
|
|
|
import { getWeekdayByText } from '../helpers/formulaFnHelper'; |
|
|
|
|
|
|
|
|
|
const pg = { |
|
|
|
|
...commonFns, |
|
|
|
@ -63,19 +65,17 @@ const pg = {
|
|
|
|
|
END${colAlias}` |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
// WEEKDAY: ({ fn, knex, pt, colAlias }: MapFnArgs) => {
|
|
|
|
|
// // isodow: the day of the week as Monday (1) to Sunday (7)
|
|
|
|
|
// // WEEKDAY() returns an index from 0 to 6 for Monday to Sunday
|
|
|
|
|
// return knex.raw(
|
|
|
|
|
// `(EXTRACT(ISODOW FROM ${
|
|
|
|
|
// pt.arguments[0].type === 'Literal'
|
|
|
|
|
// ? `date '${dayjs(fn(pt.arguments[0])).format('YYYY-MM-DD')}'`
|
|
|
|
|
// : fn(pt.arguments[0])
|
|
|
|
|
// }) - 1 - ${getWeekdayByText(
|
|
|
|
|
// pt?.arguments[1]?.value
|
|
|
|
|
// )} % 7 + 7) ::INTEGER % 7 ${colAlias}`
|
|
|
|
|
// );
|
|
|
|
|
// },
|
|
|
|
|
WEEKDAY: ({ fn, knex, pt, colAlias }: MapFnArgs) => { |
|
|
|
|
return knex.raw( |
|
|
|
|
`MOD(to_char(${ |
|
|
|
|
pt.arguments[0].type === 'Literal' |
|
|
|
|
? `date '${dayjs(fn(pt.arguments[0])).format('YYYY-MM-DD')}'` |
|
|
|
|
: fn(pt.arguments[0]) |
|
|
|
|
},'D') - 2 - ${getWeekdayByText( |
|
|
|
|
pt?.arguments[1]?.value |
|
|
|
|
)} + 7, 7) ${colAlias}` |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export default pg; |
|
|
|
|