@navikt/ds-react
Version:
React components from the Norwegian Labour and Welfare Administration.
41 lines • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.clampDisplayMonth = exports.clampDisplayYear = void 0;
const date_fns_1 = require("date-fns");
/**
* Makes sure the month is within the min and max daterange to avoid showing disabled months
* @note We do not warn the user if start > end now
*/
const clampDisplayMonth = ({ month, start, end, }) => {
if (!month) {
return undefined;
}
let monthToShow = month;
if (start && (0, date_fns_1.isBefore)(monthToShow, start)) {
monthToShow = start;
}
if (end && (0, date_fns_1.isAfter)(monthToShow, end)) {
monthToShow = end;
}
return (0, date_fns_1.startOfMonth)(monthToShow);
};
exports.clampDisplayMonth = clampDisplayMonth;
/**
* Makes sure the month is within the min and max daterange to avoid showing disabled months
* @note We do not warn the user if start > end now
*/
const clampDisplayYear = ({ month, start, end, }) => {
if (!month) {
return undefined;
}
let monthToShow = month;
if (start && monthToShow.getFullYear() < start.getFullYear()) {
monthToShow = start;
}
if (end && monthToShow.getFullYear() > end.getFullYear()) {
monthToShow = end;
}
return (0, date_fns_1.startOfYear)(monthToShow);
};
exports.clampDisplayYear = clampDisplayYear;
//# sourceMappingURL=clamp-dates.js.map