mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 14:17:13 +01:00
Website components. Update chart component.
This commit is contained in:
parent
d81ee3932d
commit
bdcdcd9d13
9 changed files with 165 additions and 43 deletions
28
lib/date.js
28
lib/date.js
|
|
@ -1,5 +1,5 @@
|
|||
import moment from 'moment-timezone';
|
||||
import { addMinutes } from 'date-fns';
|
||||
import { addMinutes, endOfDay, subDays, subHours } from 'date-fns';
|
||||
|
||||
export function getTimezone() {
|
||||
const tz = moment.tz.guess();
|
||||
|
|
@ -9,3 +9,29 @@ export function getTimezone() {
|
|||
export function getLocalTime(t) {
|
||||
return addMinutes(new Date(t), new Date().getTimezoneOffset());
|
||||
}
|
||||
|
||||
export function getDateRange(value) {
|
||||
const now = new Date();
|
||||
const endToday = endOfDay(now);
|
||||
|
||||
switch (value) {
|
||||
case '7d':
|
||||
return {
|
||||
startDate: subDays(endToday, 7),
|
||||
endDate: endToday,
|
||||
unit: 'day',
|
||||
};
|
||||
case '30d':
|
||||
return {
|
||||
startDate: subDays(endToday, 30),
|
||||
endDate: endToday,
|
||||
unit: 'day',
|
||||
};
|
||||
default:
|
||||
return {
|
||||
startDate: subHours(now, 24),
|
||||
endDate: now,
|
||||
unit: 'hour',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue