UNPKG

@technobuddha/library

Version:
26 lines (25 loc) 1.31 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getBeginningOfWeek = void 0; var constants_1 = require("../constants"); var modulo_1 = __importDefault(require("../modulo")); /** * Determine the start of the week for a date * * @param input The date * @param __namedParameters see {@link Options} * @default UTC false * @default firstDayOfWeek Sunday * @returns The date value for midnight on the first day of the specified week */ function getBeginningOfWeek(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(input.getUTCDay() + constants_1.daysPerWeek - firstDayOfWeek, constants_1.daysPerWeek))); return new Date(input.getFullYear(), input.getMonth(), input.getDate() - modulo_1.default(input.getDay() + constants_1.daysPerWeek - firstDayOfWeek, constants_1.daysPerWeek)); } exports.getBeginningOfWeek = getBeginningOfWeek; exports.default = getBeginningOfWeek;