mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Added yesterday option in date range selector.
This commit is contained in:
parent
0f976be5d8
commit
b5c9690780
@ -18,6 +18,10 @@ export const filterOptions = [
|
|||||||
),
|
),
|
||||||
value: '24hour',
|
value: '24hour',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: <FormattedMessage id="label.yesterday" defaultMessage="Yesterday" />,
|
||||||
|
value: '-1day',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: <FormattedMessage id="label.this-week" defaultMessage="This week" />,
|
label: <FormattedMessage id="label.this-week" defaultMessage="This week" />,
|
||||||
value: '1week',
|
value: '1week',
|
||||||
|
37
lib/date.js
37
lib/date.js
@ -7,6 +7,8 @@ import {
|
|||||||
addYears,
|
addYears,
|
||||||
subHours,
|
subHours,
|
||||||
subDays,
|
subDays,
|
||||||
|
subMonths,
|
||||||
|
subYears,
|
||||||
startOfMinute,
|
startOfMinute,
|
||||||
startOfHour,
|
startOfHour,
|
||||||
startOfDay,
|
startOfDay,
|
||||||
@ -39,7 +41,7 @@ export function getDateRange(value, locale = 'en-US') {
|
|||||||
const now = new Date();
|
const now = new Date();
|
||||||
const dateLocale = getDateLocale(locale);
|
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;
|
||||||
|
|
||||||
@ -78,6 +80,39 @@ export function getDateRange(value, locale = 'en-US') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (+num === -1) {
|
||||||
|
switch (unit) {
|
||||||
|
case 'day':
|
||||||
|
return {
|
||||||
|
startDate: subDays(startOfDay(now), 1),
|
||||||
|
endDate: subDays(endOfDay(now), 1),
|
||||||
|
unit: 'hour',
|
||||||
|
value,
|
||||||
|
};
|
||||||
|
case 'week':
|
||||||
|
return {
|
||||||
|
startDate: subDays(startOfWeek(now, { locale: dateLocale }), 7),
|
||||||
|
endDate: subDays(endOfWeek(now, { locale: dateLocale }), 1),
|
||||||
|
unit: 'day',
|
||||||
|
value,
|
||||||
|
};
|
||||||
|
case 'month':
|
||||||
|
return {
|
||||||
|
startDate: subMonths(startOfMonth(now), 1),
|
||||||
|
endDate: subMonths(endOfMonth(now), 1),
|
||||||
|
unit: 'day',
|
||||||
|
value,
|
||||||
|
};
|
||||||
|
case 'year':
|
||||||
|
return {
|
||||||
|
startDate: subYears(startOfYear(now), 1),
|
||||||
|
endDate: subYears(endOfYear(now), 1),
|
||||||
|
unit: 'month',
|
||||||
|
value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (unit) {
|
switch (unit) {
|
||||||
case 'day':
|
case 'day':
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user