UNPKG

@technobuddha/library

Version:
28 lines (27 loc) 1.47 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getISOWeeksInYear = void 0; var constants_1 = require("../constants"); var lodash_1 = require("lodash"); var modulo_1 = __importDefault(require("../modulo")); /** * Determine the number of ISO weeks within a year * * @param input A date within the year, or a year number * @param __namedParameters see {@link Options} * @default weekOneIncludes Thursday * @return The number of weeks in the year (52 or 53) */ function getISOWeeksInYear(input, _a) { var _b = _a === void 0 ? {} : _a, _c = _b.UTC, UTC = _c === void 0 ? false : _c, _d = _b.weekOneIncludes, weekOneIncludes = _d === void 0 ? constants_1.day.thursday : _d; var year = lodash_1.isNumber(input) ? input : UTC ? input.getUTCFullYear() : input.getFullYear(); var dow0 = UTC ? new Date(Date.UTC(year, constants_1.month.january, 1)).getUTCDay() : new Date(year, constants_1.month.january, 1).getDay(); var dow1 = UTC ? new Date(Date.UTC(year, constants_1.month.december, 31)).getUTCDay() : new Date(year, constants_1.month.december, 31).getDay(); var target = modulo_1.default(weekOneIncludes, constants_1.daysPerWeek); return (dow0 === target || dow1 === target) ? 53 : 52; } exports.getISOWeeksInYear = getISOWeeksInYear; exports.default = getISOWeeksInYear;