UNPKG

everyutil

Version:

A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.

23 lines (22 loc) 822 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addBusinessDays = void 0; /** * Adds N business days to a date, skipping weekends and optional holidays. * @author @dailker * @param {Date} date - The start date. * @param {number} days - Number of business days to add. * @param {Date[]} [holidays=[]] - Optional array of holidays. * @returns {Date} The resulting date. */ function addBusinessDays(date, days, holidays = []) { let result = new Date(date); while (days > 0) { result.setDate(result.getDate() + 1); if (result.getDay() !== 0 && result.getDay() !== 6 && !holidays.some(h => h.toDateString() === result.toDateString())) { days--; } } return result; } exports.addBusinessDays = addBusinessDays;