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.

18 lines (17 loc) 661 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isDateInRangeWithTolerance = void 0; /** * Checks if date falls within range allowing for some tolerance (e.g., plus/minus 1 day). * @author @dailker * @param {Date} d * @param {Date} start * @param {Date} end * @param {number} [tolerance=0] - Tolerance in days * @returns {boolean} */ function isDateInRangeWithTolerance(d, start, end, tolerance = 0) { const t = tolerance * 24 * 60 * 60 * 1000; return d.getTime() >= start.getTime() - t && d.getTime() <= end.getTime() + t; } exports.isDateInRangeWithTolerance = isDateInRangeWithTolerance;