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) • 542 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.nextWeekday = void 0;
/**
* Finds the next date that is a specific weekday.
* @author @dailker
* @param {Date} date - Start date.
* @param {number} weekday - 0=Sunday, 6=Saturday.
* @returns {Date}
*/
function nextWeekday(date, weekday) {
const result = new Date(date);
const diff = (weekday + 7 - result.getDay()) % 7 || 7;
result.setDate(result.getDate() + diff);
return result;
}
exports.nextWeekday = nextWeekday;