Fixed realtime chart for relational. Removed getDateArray. Added chart min/max dates.

This commit is contained in:
Mike Cao 2024-08-22 12:02:36 -07:00
parent 9311f0a183
commit 647dcb5f25
7 changed files with 46 additions and 46 deletions

View file

@ -273,19 +273,6 @@ export function getMinimumUnit(startDate: number | Date, endDate: number | Date)
return 'year';
}
export function getDateFromString(str: string) {
const [ymd, hms] = str.split(' ');
const [year, month, day] = ymd.split('-');
if (hms) {
const [hour, min, sec] = hms.split(':');
return new Date(+year, +month - 1, +day, +hour, +min, +sec);
}
return new Date(+year, +month - 1, +day);
}
export function getDateArray(data: any[], startDate: Date, endDate: Date, unit: string) {
const arr = [];
const { diff, add, start } = DATE_FUNCTIONS[unit];

View file

@ -12,19 +12,11 @@ import { filtersToArray } from './params';
const log = debug('umami:prisma');
const MYSQL_DATE_FORMATS = {
minute: '%Y-%m-%d %H:%i:00',
hour: '%Y-%m-%d %H:00:00',
day: '%Y-%m-%d',
month: '%Y-%m-01',
year: '%Y-01-01',
};
const POSTGRESQL_DATE_FORMATS = {
minute: 'YYYY-MM-DD HH24:MI:00',
hour: 'YYYY-MM-DD HH24:00:00',
day: 'YYYY-MM-DD',
month: 'YYYY-MM-01',
year: 'YYYY-01-01',
minute: '%Y-%m-%dT%H:%i:00Z',
hour: '%Y-%m-%dT%H:00:00Z',
day: '%Y-%m-%dT00:00:00Z',
month: '%Y-%m-01T00:00:00Z',
year: '%Y-01-01T00:00:00Z',
};
function getAddIntervalQuery(field: string, interval: string): string {
@ -68,9 +60,9 @@ function getDateSQL(field: string, unit: string, timezone?: string): string {
if (db === POSTGRESQL) {
if (timezone) {
return `to_char(date_trunc('${unit}', ${field} at time zone '${timezone}'), '${POSTGRESQL_DATE_FORMATS[unit]}')`;
return `date_trunc('${unit}', ${field} at time zone '${timezone}')`;
}
return `to_char(date_trunc('${unit}', ${field}), '${POSTGRESQL_DATE_FORMATS[unit]}')`;
return `date_trunc('${unit}', ${field})`;
}
if (db === MYSQL) {