| | import type { DateLib } from "../classes/DateLib.js"; |
| | import type { DayPickerProps } from "../types/index.js"; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | export function getNavMonths( |
| | props: Pick< |
| | DayPickerProps, |
| | | "captionLayout" |
| | | "endMonth" |
| | | "startMonth" |
| | | "today" |
| | | "timeZone" |
| | |
| | | "fromMonth" |
| | | "fromYear" |
| | | "toMonth" |
| | | "toYear" |
| | >, |
| | dateLib: DateLib, |
| | ): [start: Date | undefined, end: Date | undefined] { |
| | let { startMonth, endMonth } = props; |
| |
|
| | const { |
| | startOfYear, |
| | startOfDay, |
| | startOfMonth, |
| | endOfMonth, |
| | addYears, |
| | endOfYear, |
| | newDate, |
| | today, |
| | } = dateLib; |
| |
|
| | |
| | const { fromYear, toYear, fromMonth, toMonth } = props; |
| | if (!startMonth && fromMonth) { |
| | startMonth = fromMonth; |
| | } |
| | if (!startMonth && fromYear) { |
| | startMonth = dateLib.newDate(fromYear, 0, 1); |
| | } |
| | if (!endMonth && toMonth) { |
| | endMonth = toMonth; |
| | } |
| | if (!endMonth && toYear) { |
| | endMonth = newDate(toYear, 11, 31); |
| | } |
| |
|
| | const hasYearDropdown = |
| | props.captionLayout === "dropdown" || |
| | props.captionLayout === "dropdown-years"; |
| | if (startMonth) { |
| | startMonth = startOfMonth(startMonth); |
| | } else if (fromYear) { |
| | startMonth = newDate(fromYear, 0, 1); |
| | } else if (!startMonth && hasYearDropdown) { |
| | startMonth = startOfYear(addYears(props.today ?? today(), -100)); |
| | } |
| | if (endMonth) { |
| | endMonth = endOfMonth(endMonth); |
| | } else if (toYear) { |
| | endMonth = newDate(toYear, 11, 31); |
| | } else if (!endMonth && hasYearDropdown) { |
| | endMonth = endOfYear(props.today ?? today()); |
| | } |
| | return [ |
| | startMonth ? startOfDay(startMonth) : startMonth, |
| | endMonth ? startOfDay(endMonth) : endMonth, |
| | ]; |
| | } |
| |
|