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.

19 lines (18 loc) 628 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.previousBusinessDay = void 0; /** * Finds the previous business day before a given date, skipping weekends and holidays. * @author @dailker * @param {Date} date * @param {Date[]} [holidays=[]] * @returns {Date} */ function previousBusinessDay(date, holidays = []) { let d = new Date(date); do { d.setDate(d.getDate() - 1); } while (d.getDay() === 0 || d.getDay() === 6 || holidays.some(h => h.toDateString() === d.toDateString())); return d; } exports.previousBusinessDay = previousBusinessDay;