bc518174
王天杨
提交两个项目文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import { endOfMonth, startOfDay, startOfMonth } from 'date-fns';
import { DayPickerBase } from 'types/DayPickerBase';
/** Return the `fromDate` and `toDate` prop values values parsing the DayPicker props. */
export function parseFromToProps(
props: Pick<
DayPickerBase,
'fromYear' | 'toYear' | 'fromDate' | 'toDate' | 'fromMonth' | 'toMonth'
>
): { fromDate: Date | undefined; toDate: Date | undefined } {
const { fromYear, toYear, fromMonth, toMonth } = props;
let { fromDate, toDate } = props;
if (fromMonth) {
fromDate = startOfMonth(fromMonth);
} else if (fromYear) {
fromDate = new Date(fromYear, 0, 1);
}
if (toMonth) {
toDate = endOfMonth(toMonth);
} else if (toYear) {
toDate = new Date(toYear, 11, 31);
}
return {
fromDate: fromDate ? startOfDay(fromDate) : undefined,
toDate: toDate ? startOfDay(toDate) : undefined
};
}
|