1 | import type { DateLib, DayPickerProps } from "../types/index.js";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export function getNextMonth(
|
13 | firstDisplayedMonth: Date,
|
14 | calendarEndMonth: Date | undefined,
|
15 | options: Pick<
|
16 | DayPickerProps,
|
17 | "numberOfMonths" | "pagedNavigation" | "disableNavigation"
|
18 | >,
|
19 | dateLib: DateLib
|
20 | ): Date | undefined {
|
21 | if (options.disableNavigation) {
|
22 | return undefined;
|
23 | }
|
24 | const { pagedNavigation, numberOfMonths = 1 } = options;
|
25 | const { startOfMonth, addMonths, differenceInCalendarMonths } = dateLib;
|
26 | const offset = pagedNavigation ? numberOfMonths : 1;
|
27 | const month = startOfMonth(firstDisplayedMonth);
|
28 |
|
29 | if (!calendarEndMonth) {
|
30 | return addMonths(month, offset);
|
31 | }
|
32 |
|
33 | const monthsDiff = differenceInCalendarMonths(
|
34 | calendarEndMonth,
|
35 | firstDisplayedMonth
|
36 | );
|
37 |
|
38 | if (monthsDiff < numberOfMonths) {
|
39 | return undefined;
|
40 | }
|
41 |
|
42 |
|
43 | return addMonths(month, offset);
|
44 | }
|