update date range parser and date picker

This commit is contained in:
Maxime-J 2023-09-09 09:38:16 +00:00
parent c7275ef85b
commit 9b501d03e9
2 changed files with 6 additions and 12 deletions

View File

@ -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()}`);
} }
}; };

View File

@ -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('-');