@navikt/ds-react
Version:
React components from the Norwegian Labour and Welfare Administration.
30 lines • 1.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.calendarRange = calendarRange;
const date_fns_1 = require("date-fns");
/**
* Generates the min and max-dates possible to show and navigate to in the calendar.
* In the cases there is not a startMonth or endMonth, and layout is "label" no min or max dates are set.
* @returns Return the start and end months for the calendar navigation.
*/
function calendarRange({ captionLayout, startMonth, endMonth, today, }) {
const hasYearDropdown = captionLayout === "dropdown";
const todayDate = today !== null && today !== void 0 ? today : new Date();
if (startMonth) {
startMonth = (0, date_fns_1.startOfMonth)(startMonth);
}
else if (!startMonth && hasYearDropdown) {
startMonth = (0, date_fns_1.startOfYear)((0, date_fns_1.addYears)(todayDate, -100));
}
if (endMonth) {
endMonth = (0, date_fns_1.endOfMonth)(endMonth);
}
else if (!endMonth && hasYearDropdown) {
endMonth = (0, date_fns_1.endOfYear)(todayDate);
}
return [
startMonth ? (0, date_fns_1.startOfDay)(startMonth) : startMonth,
endMonth ? (0, date_fns_1.startOfDay)(endMonth) : endMonth,
];
}
//# sourceMappingURL=calendar-range.js.map