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.

24 lines (23 loc) 706 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dateDiffInBusinessDays = void 0; /** * Counts business days between two dates. * @author @dailker * @param {Date} start * @param {Date} end * @param {Date[]} [holidays=[]] * @returns {number} */ function dateDiffInBusinessDays(start, end, holidays = []) { let count = 0; let d = new Date(start); while (d <= end) { if (d.getDay() !== 0 && d.getDay() !== 6 && !holidays.some(h => h.toDateString() === d.toDateString())) { count++; } d.setDate(d.getDate() + 1); } return count; } exports.dateDiffInBusinessDays = dateDiffInBusinessDays;