UNPKG

colombian-holidays

Version:
23 lines 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.holidaysWithinInterval = void 0; const getHolidaysByYear_1 = require("./getHolidaysByYear"); function holidaysWithinInterval({ start, end, valueAsDate = false, }) { if (start >= end) { throw new Error("end date should be greater than start date"); } const yearEnd = end.getUTCFullYear(); const yearStart = start.getUTCFullYear(); const holidays = Array.from({ length: yearEnd - yearStart + 1 }, (_, i) => (0, getHolidaysByYear_1.getHolidaysForYear)(i + yearStart, { valueAsDate: true })).flat(); const holidaysWithin = holidays.filter(({ celebrationDate }) => celebrationDate >= start && celebrationDate <= end); if (valueAsDate) { return holidaysWithin; } return holidaysWithin.map((holiday) => ({ ...holiday, date: holiday.date.toISOString().slice(0, 10), celebrationDate: holiday.celebrationDate.toISOString().slice(0, 10), })); } exports.holidaysWithinInterval = holidaysWithinInterval; //# sourceMappingURL=holidaysWithinInterval.js.map