mirror of
https://github.com/kremalicious/umami.git
synced 2024-06-30 05:31:50 +02: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 { useState } from 'react';
|
||||||
import { Button, ButtonGroup, Calendar } from 'react-basics';
|
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 useLocale from 'components/hooks/useLocale';
|
||||||
import { getDateLocale } from 'lib/lang';
|
import { getDateLocale } from 'lib/lang';
|
||||||
import { FILTER_DAY, FILTER_RANGE } from 'lib/constants';
|
import { FILTER_DAY, FILTER_RANGE } from 'lib/constants';
|
||||||
|
@ -31,9 +31,9 @@ export function DatePickerForm({
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
if (selected === FILTER_DAY) {
|
if (selected === FILTER_DAY) {
|
||||||
onChange(`range:${singleDate.getTime()}:${singleDate.getTime()}`);
|
onChange(`range:${startOfDay(singleDate).getTime()}:${endOfDay(singleDate).getTime()}`);
|
||||||
} else {
|
} 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);
|
const endDate = new Date(+endTime);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...getDateRangeValues(startDate, endDate),
|
startDate,
|
||||||
|
endDate,
|
||||||
|
unit: getMinimumUnit(startDate, endDate),
|
||||||
value,
|
value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -255,14 +257,6 @@ export function getMinimumUnit(startDate, endDate) {
|
||||||
return 'year';
|
return 'year';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDateRangeValues(startDate, endDate) {
|
|
||||||
return {
|
|
||||||
startDate: startOfDay(startDate),
|
|
||||||
endDate: endOfDay(endDate),
|
|
||||||
unit: getMinimumUnit(startDate, endDate),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getDateFromString(str) {
|
export function getDateFromString(str) {
|
||||||
const [ymd, hms] = str.split(' ');
|
const [ymd, hms] = str.split(' ');
|
||||||
const [year, month, day] = ymd.split('-');
|
const [year, month, day] = ymd.split('-');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user