|
|
@ -108,6 +108,24 @@ const mssql = { |
|
|
|
END${colAlias}` |
|
|
|
END${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
|
|
|
|
|
|
|
|
const m = { |
|
|
|
|
|
|
|
monday: 0, |
|
|
|
|
|
|
|
tuesday: 1, |
|
|
|
|
|
|
|
wednesday: 2, |
|
|
|
|
|
|
|
thursday: 3, |
|
|
|
|
|
|
|
friday: 4, |
|
|
|
|
|
|
|
saturday: 5, |
|
|
|
|
|
|
|
sunday: 6, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
return knex.raw( |
|
|
|
|
|
|
|
`(DATEPART(WEEKDAY, ${fn(pt.arguments[0])}) - 2 - ${ |
|
|
|
|
|
|
|
m[pt?.arguments[1]?.value.toLowerCase()] || 0 |
|
|
|
|
|
|
|
} % 7 + 7) % 7 ${colAlias}` |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default mssql; |
|
|
|
export default mssql; |
|
|
|