mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-01 12:29:35 +01:00
update date range parser and date picker
This commit is contained in:
parent
c7275ef85b
commit
9b501d03e9
@ -1,6 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { Button, ButtonGroup, Calendar } from 'react-basics';
|
||||
import { isAfter, isBefore, isSameDay } from 'date-fns';
|
||||
import { isAfter, isBefore, isSameDay, startOfDay, endOfDay } from 'date-fns';
|
||||
import useLocale from 'components/hooks/useLocale';
|
||||
import { getDateLocale } from 'lib/lang';
|
||||
import { FILTER_DAY, FILTER_RANGE } from 'lib/constants';
|
||||
@ -31,9 +31,9 @@ export function DatePickerForm({
|
||||
|
||||
const handleSave = () => {
|
||||
if (selected === FILTER_DAY) {
|
||||
onChange(`range:${singleDate.getTime()}:${singleDate.getTime()}`);
|
||||
onChange(`range:${startOfDay(singleDate).getTime()}:${endOfDay(singleDate).getTime()}`);
|
||||
} else {
|
||||
onChange(`range:${startDate.getTime()}:${endDate.getTime()}`);
|
||||
onChange(`range:${startOfDay(startDate).getTime()}:${endOfDay(endDate).getTime()}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -78,7 +78,9 @@ export function parseDateRange(value, locale = 'en-US') {
|
||||
const endDate = new Date(+endTime);
|
||||
|
||||
return {
|
||||
...getDateRangeValues(startDate, endDate),
|
||||
startDate,
|
||||
endDate,
|
||||
unit: getMinimumUnit(startDate, endDate),
|
||||
value,
|
||||
};
|
||||
}
|
||||
@ -255,14 +257,6 @@ export function getMinimumUnit(startDate, endDate) {
|
||||
return 'year';
|
||||
}
|
||||
|
||||
export function getDateRangeValues(startDate, endDate) {
|
||||
return {
|
||||
startDate: startOfDay(startDate),
|
||||
endDate: endOfDay(endDate),
|
||||
unit: getMinimumUnit(startDate, endDate),
|
||||
};
|
||||
}
|
||||
|
||||
export function getDateFromString(str) {
|
||||
const [ymd, hms] = str.split(' ');
|
||||
const [year, month, day] = ymd.split('-');
|
||||
|
Loading…
Reference in New Issue
Block a user