mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 22:57:12 +01:00
Updated date range handling.
This commit is contained in:
parent
bfb52eb678
commit
e9b0d3f796
4 changed files with 25 additions and 15 deletions
19
lib/date.js
19
lib/date.js
|
|
@ -40,20 +40,27 @@ export function getLocalTime(t) {
|
|||
|
||||
export function parseDateRange(value, locale = 'en-US') {
|
||||
if (typeof value === 'object') {
|
||||
const { startDate, endDate } = value;
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value?.startsWith?.('range')) {
|
||||
const [, startAt, endAt] = value.split(':');
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
return {
|
||||
...value,
|
||||
startDate: typeof startDate === 'string' ? parseISO(startDate) : startDate,
|
||||
endDate: typeof endDate === 'string' ? parseISO(endDate) : endDate,
|
||||
...getDateRangeValues(startDate, endDate),
|
||||
value,
|
||||
};
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const dateLocale = getDateLocale(locale);
|
||||
|
||||
const match = value.match(/^(?<num>[0-9-]+)(?<unit>hour|day|week|month|year)$/);
|
||||
const match = value?.match?.(/^(?<num>[0-9-]+)(?<unit>hour|day|week|month|year)$/);
|
||||
|
||||
if (!match) return {};
|
||||
if (!match) return null;
|
||||
|
||||
const { num, unit } = match.groups;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue