@technobuddha/library
Version:
A large library of useful functions
26 lines (25 loc) • 1.3 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEndOfWeek = void 0;
var constants_1 = require("../constants");
var modulo_1 = __importDefault(require("../modulo"));
/**
* Determine the last day of the week containing a date
*
* @param input The date
* @param __namedParameters see {@link Options}
* @default UTC false
* @default firstDayOfWeek Sunday
* @returns Midnight of the last day of the week containing the input date
*/
function getEndOfWeek(input, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.UTC, UTC = _c === void 0 ? false : _c, _d = _b.firstDayOfWeek, firstDayOfWeek = _d === void 0 ? constants_1.day.sunday : _d;
if (UTC)
return new Date(Date.UTC(input.getUTCFullYear(), input.getUTCMonth(), input.getUTCDate() + modulo_1.default(constants_1.daysPerWeek - input.getUTCDay() + firstDayOfWeek - 1, constants_1.daysPerWeek)));
return new Date(input.getFullYear(), input.getMonth(), input.getDate() + modulo_1.default(constants_1.daysPerWeek - input.getDay() + firstDayOfWeek - 1, constants_1.daysPerWeek));
}
exports.getEndOfWeek = getEndOfWeek;
exports.default = getEndOfWeek;