Weekly session data.
This commit is contained in:
@@ -34,6 +34,7 @@ import {
|
||||
addWeeks,
|
||||
subWeeks,
|
||||
endOfMinute,
|
||||
isSameDay,
|
||||
} from 'date-fns';
|
||||
import { getDateLocale } from 'lib/lang';
|
||||
import { DateRange } from 'lib/types';
|
||||
@@ -336,3 +337,16 @@ export function getCompareDate(compare: string, startDate: Date, endDate: Date)
|
||||
|
||||
return { startDate: subMinutes(startDate, diff), endDate: subMinutes(endDate, diff) };
|
||||
}
|
||||
|
||||
export function getDayOfWeekAsDate(dayOfWeek: number) {
|
||||
const startOfWeekDay = startOfWeek(new Date());
|
||||
const daysToAdd = [0, 1, 2, 3, 4, 5, 6].indexOf(dayOfWeek);
|
||||
let currentDate = addDays(startOfWeekDay, daysToAdd);
|
||||
|
||||
// Ensure we're not returning a past date
|
||||
if (isSameDay(currentDate, startOfWeekDay)) {
|
||||
currentDate = addDays(currentDate, 7);
|
||||
}
|
||||
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
@@ -81,6 +81,18 @@ function getDateSQL(field: string, unit: string, timezone?: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
function getDateWeeklySQL(field: string) {
|
||||
const db = getDatabaseType();
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
return `EXTRACT(DOW FROM ${field})`;
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
return `DAYOFWEEK(${field})-1`;
|
||||
}
|
||||
}
|
||||
|
||||
export function getTimestampSQL(field: string) {
|
||||
const db = getDatabaseType();
|
||||
|
||||
@@ -284,6 +296,7 @@ export default {
|
||||
getCastColumnQuery,
|
||||
getDayDiffQuery,
|
||||
getDateSQL,
|
||||
getDateWeeklySQL,
|
||||
getFilterQuery,
|
||||
getSearchParameters,
|
||||
getTimestampDiffSQL,
|
||||
|
||||
Reference in New Issue
Block a user