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
|
import { addMonths, differenceInCalendarMonths, startOfMonth } from 'date-fns';
/**
* Return the months to display in the component according to the number of
* months and the from/to date.
*/
export function getDisplayMonths(
month: Date,
{
reverseMonths,
numberOfMonths
}: {
reverseMonths?: boolean;
numberOfMonths: number;
}
): Date[] {
const start = startOfMonth(month);
const end = startOfMonth(addMonths(start, numberOfMonths));
const monthsDiff = differenceInCalendarMonths(end, start);
let months = [];
for (let i = 0; i < monthsDiff; i++) {
const nextMonth = addMonths(start, i);
months.push(nextMonth);
}
if (reverseMonths) months = months.reverse();
return months;
}
|