mirror of
https://github.com/umami-software/umami.git
synced 2026-02-18 11:35:37 +01:00
chore: added all time range
This commit is contained in:
parent
c4307db1b8
commit
9fbcb286fe
7 changed files with 104 additions and 82 deletions
49
lib/date.js
49
lib/date.js
|
|
@ -1,32 +1,32 @@
|
|||
import moment from 'moment-timezone';
|
||||
import {
|
||||
addMinutes,
|
||||
addHours,
|
||||
addDays,
|
||||
addHours,
|
||||
addMinutes,
|
||||
addMonths,
|
||||
addYears,
|
||||
subHours,
|
||||
subDays,
|
||||
startOfMinute,
|
||||
startOfHour,
|
||||
startOfDay,
|
||||
startOfWeek,
|
||||
startOfMonth,
|
||||
startOfYear,
|
||||
endOfHour,
|
||||
endOfDay,
|
||||
endOfWeek,
|
||||
endOfMonth,
|
||||
endOfYear,
|
||||
differenceInMinutes,
|
||||
differenceInHours,
|
||||
differenceInCalendarDays,
|
||||
differenceInCalendarMonths,
|
||||
differenceInCalendarYears,
|
||||
differenceInHours,
|
||||
differenceInMinutes,
|
||||
endOfDay,
|
||||
endOfHour,
|
||||
endOfMonth,
|
||||
endOfWeek,
|
||||
endOfYear,
|
||||
format,
|
||||
startOfDay,
|
||||
startOfHour,
|
||||
startOfMinute,
|
||||
startOfMonth,
|
||||
startOfWeek,
|
||||
startOfYear,
|
||||
subDays,
|
||||
subHours,
|
||||
} from 'date-fns';
|
||||
import { enUS } from 'date-fns/locale';
|
||||
import { dateLocales } from 'lib/lang';
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
export function getTimezone() {
|
||||
return moment.tz.guess();
|
||||
|
|
@ -36,11 +36,20 @@ export function getLocalTime(t) {
|
|||
return addMinutes(new Date(t), new Date().getTimezoneOffset());
|
||||
}
|
||||
|
||||
export function getDateRange(value, locale = 'en-US') {
|
||||
export function getDateRange(value, locale = 'en-US', createdAt) {
|
||||
const now = new Date();
|
||||
const localeOptions = dateLocales[locale];
|
||||
|
||||
const { num, unit } = value.match(/^(?<num>[0-9]+)(?<unit>hour|day|week|month|year)$/).groups;
|
||||
const { num, unit } = value.match(/^(?<num>[0-9]+)(?<unit>hour|day|week|month|year|all)$/).groups;
|
||||
|
||||
if (unit === 'all') {
|
||||
return {
|
||||
startDate: startOfMonth(new Date(createdAt)),
|
||||
endDate: endOfYear(now),
|
||||
unit: 'month',
|
||||
value,
|
||||
};
|
||||
}
|
||||
|
||||
if (+num === 1) {
|
||||
switch (unit) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue