UNPKG

rrule

Version:

JavaScript library for working with recurrence rules for calendar dates.

1,238 lines (1,220 loc) 130 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("luxon")); else if(typeof define === 'function' && define.amd) define(["luxon"], factory); else if(typeof exports === 'object') exports["rrule"] = factory(require("luxon")); else root["rrule"] = factory(root["luxon"]); })(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE__2__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 1); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "f", function() { return isPresent; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "e", function() { return isNumber; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "d", function() { return isArray; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "j", function() { return range; }); /* unused harmony export clone */ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "k", function() { return repeat; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "m", function() { return toArray; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "h", function() { return padStart; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "l", function() { return split; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "i", function() { return pymod; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return divmod; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return empty; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "g", function() { return notEmpty; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return includes; }); // ============================================================================= // Helper functions // ============================================================================= var isPresent = function (value) { return value !== null && value !== undefined; }; var isNumber = function (value) { return typeof value === 'number'; }; var isArray = Array.isArray; /** * Simplified version of python's range() */ var range = function (start, end) { if (end === void 0) { end = start; } if (arguments.length === 1) { end = start; start = 0; } var rang = []; for (var i = start; i < end; i++) rang.push(i); return rang; }; var clone = function (array) { return [].concat(array); }; var repeat = function (value, times) { var i = 0; var array = []; if (isArray(value)) { for (; i < times; i++) array[i] = [].concat(value); } else { for (; i < times; i++) array[i] = value; } return array; }; var toArray = function (item) { if (isArray(item)) { return item; } return [item]; }; function padStart(item, targetLength, padString) { if (padString === void 0) { padString = ' '; } var str = String(item); targetLength = targetLength >> 0; if (str.length > targetLength) { return String(str); } targetLength = targetLength - str.length; if (targetLength > padString.length) { padString += repeat(padString, targetLength / padString.length); } return padString.slice(0, targetLength) + String(str); } /** * Python like split */ var split = function (str, sep, num) { var splits = str.split(sep); return num ? splits.slice(0, num).concat([splits.slice(num).join(sep)]) : splits; }; /** * closure/goog/math/math.js:modulo * Copyright 2006 The Closure Library Authors. * The % operator in JavaScript returns the remainder of a / b, but differs from * some other languages in that the result will have the same sign as the * dividend. For example, -1 % 8 == -1, whereas in some other languages * (such as Python) the result would be 7. This function emulates the more * correct modulo behavior, which is useful for certain applications such as * calculating an offset index in a circular list. * * @param {number} a The dividend. * @param {number} b The divisor. * @return {number} a % b where the result is between 0 and b (either 0 <= x < b * or b < x <= 0, depending on the sign of b). */ var pymod = function (a, b) { var r = a % b; // If r and b differ in sign, add b to wrap the result to the correct sign. return r * b < 0 ? r + b : r; }; /** * @see: <http://docs.python.org/library/functions.html#divmod> */ var divmod = function (a, b) { return { div: Math.floor(a / b), mod: pymod(a, b) }; }; var empty = function (obj) { return !isPresent(obj) || obj.length === 0; }; /** * Python-like boolean * @return {Boolean} value of an object/primitive, taking into account * the fact that in Python an empty list's/tuple's * boolean value is False, whereas in JS it's true */ var notEmpty = function (obj) { return !empty(obj); }; /** * Return true if a value is in an array */ var includes = function (arr, val) { return notEmpty(arr) && arr.indexOf(val) !== -1; }; //# sourceMappingURL=helpers.js.map /***/ }), /* 1 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); // EXTERNAL MODULE: ./dist/esm/helpers.js var helpers = __webpack_require__(0); // CONCATENATED MODULE: ./dist/esm/dateutil.js var __extends = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * General date-related utilities. * Also handles several incompatibilities between JavaScript and Python * */ var dateutil_dateutil; (function (dateutil) { dateutil.MONTH_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; /** * Number of milliseconds of one day */ dateutil.ONE_DAY = 1000 * 60 * 60 * 24; /** * @see: <http://docs.python.org/library/datetime.html#datetime.MAXYEAR> */ dateutil.MAXYEAR = 9999; /** * Python uses 1-Jan-1 as the base for calculating ordinals but we don't * want to confuse the JS engine with milliseconds > Number.MAX_NUMBER, * therefore we use 1-Jan-1970 instead */ dateutil.ORDINAL_BASE = new Date(Date.UTC(1970, 0, 1)); /** * Python: MO-SU: 0 - 6 * JS: SU-SAT 0 - 6 */ dateutil.PY_WEEKDAYS = [6, 0, 1, 2, 3, 4, 5]; /** * py_date.timetuple()[7] */ dateutil.getYearDay = function (date) { var dateNoTime = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()); return (Math.ceil((dateNoTime.valueOf() - new Date(date.getUTCFullYear(), 0, 1).valueOf()) / dateutil.ONE_DAY) + 1); }; dateutil.isLeapYear = function (year) { return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; }; /** * @return {Number} the date's timezone offset in ms */ dateutil.tzOffset = function (date) { return date.getTimezoneOffset() * 60 * 1000; }; /** * @see: <http://www.mcfedries.com/JavaScript/DaysBetween.asp> */ dateutil.daysBetween = function (date1, date2) { // The number of milliseconds in one day // Convert both dates to milliseconds var date1ms = date1.getTime() - dateutil.tzOffset(date1); var date2ms = date2.getTime() - dateutil.tzOffset(date2); // Calculate the difference in milliseconds var differencems = date1ms - date2ms; // Convert back to days and return return Math.round(differencems / dateutil.ONE_DAY); }; /** * @see: <http://docs.python.org/library/datetime.html#datetime.date.toordinal> */ dateutil.toOrdinal = function (date) { return dateutil.daysBetween(date, dateutil.ORDINAL_BASE); }; /** * @see - <http://docs.python.org/library/datetime.html#datetime.date.fromordinal> */ dateutil.fromOrdinal = function (ordinal) { return new Date(dateutil.ORDINAL_BASE.getTime() + ordinal * dateutil.ONE_DAY); }; dateutil.getMonthDays = function (date) { var month = date.getUTCMonth(); return month === 1 && dateutil.isLeapYear(date.getUTCFullYear()) ? 29 : dateutil.MONTH_DAYS[month]; }; /** * @return {Number} python-like weekday */ dateutil.getWeekday = function (date) { return dateutil.PY_WEEKDAYS[date.getUTCDay()]; }; /** * @see: <http://docs.python.org/library/calendar.html#calendar.monthrange> */ dateutil.monthRange = function (year, month) { var date = new Date(Date.UTC(year, month, 1)); return [dateutil.getWeekday(date), dateutil.getMonthDays(date)]; }; /** * @see: <http://docs.python.org/library/datetime.html#datetime.datetime.combine> */ dateutil.combine = function (date, time) { time = time || date; return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), time.getHours(), time.getMinutes(), time.getSeconds(), time.getMilliseconds())); }; dateutil.clone = function (date) { var dolly = new Date(date.getTime()); return dolly; }; dateutil.cloneDates = function (dates) { var clones = []; for (var i = 0; i < dates.length; i++) { clones.push(dateutil.clone(dates[i])); } return clones; }; /** * Sorts an array of Date or dateutil.Time objects */ dateutil.sort = function (dates) { dates.sort(function (a, b) { return a.getTime() - b.getTime(); }); }; dateutil.timeToUntilString = function (time, utc) { if (utc === void 0) { utc = true; } var date = new Date(time); return [ Object(helpers["h" /* padStart */])(date.getUTCFullYear().toString(), 4, '0'), Object(helpers["h" /* padStart */])(date.getUTCMonth() + 1, 2, '0'), Object(helpers["h" /* padStart */])(date.getUTCDate(), 2, '0'), 'T', Object(helpers["h" /* padStart */])(date.getUTCHours(), 2, '0'), Object(helpers["h" /* padStart */])(date.getUTCMinutes(), 2, '0'), Object(helpers["h" /* padStart */])(date.getUTCSeconds(), 2, '0'), utc ? 'Z' : '' ].join(''); }; dateutil.untilStringToDate = function (until) { var re = /^(\d{4})(\d{2})(\d{2})(T(\d{2})(\d{2})(\d{2})Z?)?$/; var bits = re.exec(until); if (!bits) throw new Error("Invalid UNTIL value: " + until); return new Date(Date.UTC(parseInt(bits[1], 10), parseInt(bits[2], 10) - 1, parseInt(bits[3], 10), parseInt(bits[5], 10) || 0, parseInt(bits[6], 10) || 0, parseInt(bits[7], 10) || 0)); }; var Time = /** @class */ (function () { function Time(hour, minute, second, millisecond) { this.hour = hour; this.minute = minute; this.second = second; this.millisecond = millisecond || 0; } Time.prototype.getHours = function () { return this.hour; }; Time.prototype.getMinutes = function () { return this.minute; }; Time.prototype.getSeconds = function () { return this.second; }; Time.prototype.getMilliseconds = function () { return this.millisecond; }; Time.prototype.getTime = function () { return ((this.hour * 60 * 60 + this.minute * 60 + this.second) * 1000 + this.millisecond); }; return Time; }()); dateutil.Time = Time; var DateTime = /** @class */ (function (_super) { __extends(DateTime, _super); function DateTime(year, month, day, hour, minute, second, millisecond) { var _this = _super.call(this, hour, minute, second, millisecond) || this; _this.year = year; _this.month = month; _this.day = day; return _this; } DateTime.prototype.getWeekday = function () { return dateutil.getWeekday(new Date(this.getTime())); }; DateTime.prototype.getTime = function () { return new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, this.millisecond)).getTime(); }; DateTime.prototype.getDay = function () { return this.day; }; DateTime.prototype.getMonth = function () { return this.month; }; DateTime.prototype.getYear = function () { return this.year; }; DateTime.prototype.addYears = function (years) { this.year += years; }; DateTime.prototype.addMonths = function (months) { this.month += months; if (this.month > 12) { var yearDiv = Math.floor(this.month / 12); var monthMod = Object(helpers["i" /* pymod */])(this.month, 12); this.month = monthMod; this.year += yearDiv; if (this.month === 0) { this.month = 12; --this.year; } } }; DateTime.prototype.addWeekly = function (days, wkst) { if (wkst > this.getWeekday()) { this.day += -(this.getWeekday() + 1 + (6 - wkst)) + days * 7; } else { this.day += -(this.getWeekday() - wkst) + days * 7; } this.fixDay(); }; DateTime.prototype.addDaily = function (days) { this.day += days; this.fixDay(); }; DateTime.prototype.addHours = function (hours, filtered, byhour) { var fixday = false; if (filtered) { // Jump to one iteration before next day this.hour += Math.floor((23 - this.hour) / hours) * hours; } while (true) { this.hour += hours; var _a = Object(helpers["a" /* divmod */])(this.hour, 24), dayDiv = _a.div, hourMod = _a.mod; if (dayDiv) { this.hour = hourMod; this.addDaily(dayDiv); fixday = true; } if (Object(helpers["b" /* empty */])(byhour) || Object(helpers["c" /* includes */])(byhour, this.hour)) break; } return fixday; }; DateTime.prototype.addMinutes = function (minutes, filtered, byhour, byminute) { var fixday = false; if (filtered) { // Jump to one iteration before next day this.minute += Math.floor((1439 - (this.hour * 60 + this.minute)) / minutes) * minutes; } while (true) { this.minute += minutes; var _a = Object(helpers["a" /* divmod */])(this.minute, 60), hourDiv = _a.div, minuteMod = _a.mod; if (hourDiv) { this.minute = minuteMod; fixday = this.addHours(hourDiv, false, byhour); } if ((Object(helpers["b" /* empty */])(byhour) || Object(helpers["c" /* includes */])(byhour, this.hour)) && (Object(helpers["b" /* empty */])(byminute) || Object(helpers["c" /* includes */])(byminute, this.minute))) { break; } } return fixday; }; DateTime.prototype.addSeconds = function (seconds, filtered, byhour, byminute, bysecond) { var fixday = false; if (filtered) { // Jump to one iteration before next day this.second += Math.floor((86399 - (this.hour * 3600 + this.minute * 60 + this.second)) / seconds) * seconds; } while (true) { this.second += seconds; var _a = Object(helpers["a" /* divmod */])(this.second, 60), minuteDiv = _a.div, secondMod = _a.mod; if (minuteDiv) { this.second = secondMod; fixday = this.addMinutes(minuteDiv, false, byhour, byminute); } if ((Object(helpers["b" /* empty */])(byhour) || Object(helpers["c" /* includes */])(byhour, this.hour)) && (Object(helpers["b" /* empty */])(byminute) || Object(helpers["c" /* includes */])(byminute, this.minute)) && (Object(helpers["b" /* empty */])(bysecond) || Object(helpers["c" /* includes */])(bysecond, this.second))) { break; } } return fixday; }; DateTime.prototype.fixDay = function () { if (this.day <= 28) { return; } var daysinmonth = dateutil.monthRange(this.year, this.month - 1)[1]; if (this.day <= daysinmonth) { return; } while (this.day > daysinmonth) { this.day -= daysinmonth; ++this.month; if (this.month === 13) { this.month = 1; ++this.year; if (this.year > dateutil.MAXYEAR) { return; } } daysinmonth = dateutil.monthRange(this.year, this.month - 1)[1]; } }; return DateTime; }(Time)); dateutil.DateTime = DateTime; })(dateutil_dateutil || (dateutil_dateutil = {})); /* harmony default export */ var esm_dateutil = (dateutil_dateutil); //# sourceMappingURL=dateutil.js.map // CONCATENATED MODULE: ./dist/esm/masks.js // ============================================================================= // Date masks // ============================================================================= // Every mask is 7 days longer to handle cross-year weekly periods. var M365MASK = Object(helpers["k" /* repeat */])(1, 31).concat(Object(helpers["k" /* repeat */])(2, 28), Object(helpers["k" /* repeat */])(3, 31), Object(helpers["k" /* repeat */])(4, 30), Object(helpers["k" /* repeat */])(5, 31), Object(helpers["k" /* repeat */])(6, 30), Object(helpers["k" /* repeat */])(7, 31), Object(helpers["k" /* repeat */])(8, 31), Object(helpers["k" /* repeat */])(9, 30), Object(helpers["k" /* repeat */])(10, 31), Object(helpers["k" /* repeat */])(11, 30), Object(helpers["k" /* repeat */])(12, 31), Object(helpers["k" /* repeat */])(1, 7)); var M366MASK = Object(helpers["k" /* repeat */])(1, 31).concat(Object(helpers["k" /* repeat */])(2, 29), Object(helpers["k" /* repeat */])(3, 31), Object(helpers["k" /* repeat */])(4, 30), Object(helpers["k" /* repeat */])(5, 31), Object(helpers["k" /* repeat */])(6, 30), Object(helpers["k" /* repeat */])(7, 31), Object(helpers["k" /* repeat */])(8, 31), Object(helpers["k" /* repeat */])(9, 30), Object(helpers["k" /* repeat */])(10, 31), Object(helpers["k" /* repeat */])(11, 30), Object(helpers["k" /* repeat */])(12, 31), Object(helpers["k" /* repeat */])(1, 7)); var M28 = Object(helpers["j" /* range */])(1, 29); var M29 = Object(helpers["j" /* range */])(1, 30); var M30 = Object(helpers["j" /* range */])(1, 31); var M31 = Object(helpers["j" /* range */])(1, 32); var MDAY366MASK = M31.concat(M29, M31, M30, M31, M30, M31, M31, M30, M31, M30, M31, M31.slice(0, 7)); var MDAY365MASK = M31.concat(M28, M31, M30, M31, M30, M31, M31, M30, M31, M30, M31, M31.slice(0, 7)); var NM28 = Object(helpers["j" /* range */])(-28, 0); var NM29 = Object(helpers["j" /* range */])(-29, 0); var NM30 = Object(helpers["j" /* range */])(-30, 0); var NM31 = Object(helpers["j" /* range */])(-31, 0); var NMDAY366MASK = NM31.concat(NM29, NM31, NM30, NM31, NM30, NM31, NM31, NM30, NM31, NM30, NM31, NM31.slice(0, 7)); var NMDAY365MASK = NM31.concat(NM28, NM31, NM30, NM31, NM30, NM31, NM31, NM30, NM31, NM30, NM31, NM31.slice(0, 7)); var M366RANGE = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366]; var M365RANGE = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365]; var WDAYMASK = (function () { var wdaymask = []; for (var i = 0; i < 55; i++) wdaymask = wdaymask.concat(Object(helpers["j" /* range */])(7)); return wdaymask; })(); //# sourceMappingURL=masks.js.map // CONCATENATED MODULE: ./dist/esm/iterinfo.js // ============================================================================= // Iterinfo // ============================================================================= var iterinfo_Iterinfo = /** @class */ (function () { function Iterinfo(rrule) { this.yearlen = 365; this.nextyearlen = 365; this.rrule = rrule; this.mmask = null; this.mrange = null; this.mdaymask = null; this.nmdaymask = null; this.wdaymask = null; this.wnomask = null; this.nwdaymask = null; this.eastermask = null; } Iterinfo.prototype.easter = function (y, offset) { if (offset === void 0) { offset = 0; } var a = y % 19; var b = Math.floor(y / 100); var c = y % 100; var d = Math.floor(b / 4); var e = b % 4; var f = Math.floor((b + 8) / 25); var g = Math.floor((b - f + 1) / 3); var h = Math.floor(19 * a + b - d - g + 15) % 30; var i = Math.floor(c / 4); var k = c % 4; var l = Math.floor(32 + 2 * e + 2 * i - h - k) % 7; var m = Math.floor((a + 11 * h + 22 * l) / 451); var month = Math.floor((h + l - 7 * m + 114) / 31); var day = ((h + l - 7 * m + 114) % 31) + 1; var date = Date.UTC(y, month - 1, day + offset); var yearStart = Date.UTC(y, 0, 1); return [Math.ceil((date - yearStart) / (1000 * 60 * 60 * 24))]; }; Iterinfo.prototype.rebuild = function (year, month) { var rr = this.rrule; if (year !== this.lastyear) { this.rebuildYear(year); } if (Object(helpers["g" /* notEmpty */])(rr.options.bynweekday) && (month !== this.lastmonth || year !== this.lastyear)) { this.rebuildMonth(year, month); } if (Object(helpers["f" /* isPresent */])(rr.options.byeaster)) { this.eastermask = this.easter(year, rr.options.byeaster); } }; Iterinfo.prototype.rebuildYear = function (year) { var rr = this.rrule; this.yearlen = esm_dateutil.isLeapYear(year) ? 366 : 365; this.nextyearlen = esm_dateutil.isLeapYear(year + 1) ? 366 : 365; var firstyday = new Date(Date.UTC(year, 0, 1)); this.yearordinal = esm_dateutil.toOrdinal(firstyday); this.yearweekday = esm_dateutil.getWeekday(firstyday); var wday = esm_dateutil.getWeekday(firstyday); if (this.yearlen === 365) { this.mmask = M365MASK; this.mdaymask = MDAY365MASK; this.nmdaymask = NMDAY365MASK; this.wdaymask = WDAYMASK.slice(wday); this.mrange = M365RANGE; } else { this.mmask = M366MASK; this.mdaymask = MDAY366MASK; this.nmdaymask = NMDAY366MASK; this.wdaymask = WDAYMASK.slice(wday); this.mrange = M366RANGE; } if (Object(helpers["b" /* empty */])(rr.options.byweekno)) { this.wnomask = null; } else { this.wnomask = Object(helpers["k" /* repeat */])(0, this.yearlen + 7); var no1wkst = void 0; var firstwkst = void 0; var wyearlen = void 0; no1wkst = firstwkst = Object(helpers["i" /* pymod */])(7 - this.yearweekday + rr.options.wkst, 7); if (no1wkst >= 4) { no1wkst = 0; // Number of days in the year, plus the days we got // from last year. wyearlen = this.yearlen + Object(helpers["i" /* pymod */])(this.yearweekday - rr.options.wkst, 7); } else { // Number of days in the year, minus the days we // left in last year. wyearlen = this.yearlen - no1wkst; } var div = Math.floor(wyearlen / 7); var mod = Object(helpers["i" /* pymod */])(wyearlen, 7); var numweeks = Math.floor(div + mod / 4); for (var j = 0; j < rr.options.byweekno.length; j++) { var i = void 0; var n = rr.options.byweekno[j]; if (n < 0) { n += numweeks + 1; } if (!(n > 0 && n <= numweeks)) { continue; } if (n > 1) { i = no1wkst + (n - 1) * 7; if (no1wkst !== firstwkst) { i -= 7 - firstwkst; } } else { i = no1wkst; } for (var k = 0; k < 7; k++) { this.wnomask[i] = 1; i++; if (this.wdaymask[i] === rr.options.wkst) break; } } if (Object(helpers["c" /* includes */])(rr.options.byweekno, 1)) { // Check week number 1 of next year as well // orig-TODO : Check -numweeks for next year. var i = no1wkst + numweeks * 7; if (no1wkst !== firstwkst) i -= 7 - firstwkst; if (i < this.yearlen) { // If week starts in next year, we // don't care about it. for (var j = 0; j < 7; j++) { this.wnomask[i] = 1; i += 1; if (this.wdaymask[i] === rr.options.wkst) break; } } } if (no1wkst) { // Check last week number of last year as // well. If no1wkst is 0, either the year // started on week start, or week number 1 // got days from last year, so there are no // days from last year's last week number in // this year. var lnumweeks = void 0; if (!Object(helpers["c" /* includes */])(rr.options.byweekno, -1)) { var lyearweekday = esm_dateutil.getWeekday(new Date(Date.UTC(year - 1, 0, 1))); var lno1wkst = Object(helpers["i" /* pymod */])(7 - lyearweekday.valueOf() + rr.options.wkst, 7); var lyearlen = esm_dateutil.isLeapYear(year - 1) ? 366 : 365; if (lno1wkst >= 4) { lno1wkst = 0; lnumweeks = Math.floor(52 + Object(helpers["i" /* pymod */])(lyearlen + Object(helpers["i" /* pymod */])(lyearweekday - rr.options.wkst, 7), 7) / 4); } else { lnumweeks = Math.floor(52 + Object(helpers["i" /* pymod */])(this.yearlen - no1wkst, 7) / 4); } } else { lnumweeks = -1; } if (Object(helpers["c" /* includes */])(rr.options.byweekno, lnumweeks)) { for (var i = 0; i < no1wkst; i++) this.wnomask[i] = 1; } } } }; Iterinfo.prototype.rebuildMonth = function (year, month) { var rr = this.rrule; var ranges = []; if (rr.options.freq === esm_rrule.YEARLY) { if (Object(helpers["g" /* notEmpty */])(rr.options.bymonth)) { for (var j = 0; j < rr.options.bymonth.length; j++) { month = rr.options.bymonth[j]; ranges.push(this.mrange.slice(month - 1, month + 1)); } } else { ranges = [[0, this.yearlen]]; } } else if (rr.options.freq === esm_rrule.MONTHLY) { ranges = [this.mrange.slice(month - 1, month + 1)]; } if (Object(helpers["g" /* notEmpty */])(ranges)) { // Weekly frequency won't get here, so we may not // care about cross-year weekly periods. this.nwdaymask = Object(helpers["k" /* repeat */])(0, this.yearlen); for (var j = 0; j < ranges.length; j++) { var rang = ranges[j]; var first = rang[0]; var last = rang[1]; last -= 1; for (var k = 0; k < rr.options.bynweekday.length; k++) { var i = void 0; var wday = rr.options.bynweekday[k][0]; var n = rr.options.bynweekday[k][1]; if (n < 0) { i = last + (n + 1) * 7; i -= Object(helpers["i" /* pymod */])(this.wdaymask[i] - wday, 7); } else { i = first + (n - 1) * 7; i += Object(helpers["i" /* pymod */])(7 - this.wdaymask[i] + wday, 7); } if (first <= i && i <= last) this.nwdaymask[i] = 1; } } } this.lastyear = year; this.lastmonth = month; }; Iterinfo.prototype.ydayset = function () { return [Object(helpers["j" /* range */])(this.yearlen), 0, this.yearlen]; }; Iterinfo.prototype.mdayset = function (_, month, __) { var start = this.mrange[month - 1]; var end = this.mrange[month]; var set = Object(helpers["k" /* repeat */])(null, this.yearlen); for (var i = start; i < end; i++) set[i] = i; return [set, start, end]; }; Iterinfo.prototype.wdayset = function (year, month, day) { // We need to handle cross-year weeks here. var set = Object(helpers["k" /* repeat */])(null, this.yearlen + 7); var i = esm_dateutil.toOrdinal(new Date(Date.UTC(year, month - 1, day))) - this.yearordinal; var start = i; for (var j = 0; j < 7; j++) { set[i] = i; ++i; if (this.wdaymask[i] === this.rrule.options.wkst) break; } return [set, start, i]; }; Iterinfo.prototype.ddayset = function (year, month, day) { var set = Object(helpers["k" /* repeat */])(null, this.yearlen); var i = esm_dateutil.toOrdinal(new Date(Date.UTC(year, month - 1, day))) - this.yearordinal; set[i] = i; return [set, i, i + 1]; }; Iterinfo.prototype.htimeset = function (hour, minute, second, millisecond) { var set = []; var rr = this.rrule; for (var i = 0; i < rr.options.byminute.length; i++) { minute = rr.options.byminute[i]; for (var j = 0; j < rr.options.bysecond.length; j++) { second = rr.options.bysecond[j]; set.push(new esm_dateutil.Time(hour, minute, second, millisecond)); } } esm_dateutil.sort(set); return set; }; Iterinfo.prototype.mtimeset = function (hour, minute, second, millisecond) { var set = []; var rr = this.rrule; for (var j = 0; j < rr.options.bysecond.length; j++) { second = rr.options.bysecond[j]; set.push(new esm_dateutil.Time(hour, minute, second, millisecond)); } esm_dateutil.sort(set); return set; }; Iterinfo.prototype.stimeset = function (hour, minute, second, millisecond) { return [new esm_dateutil.Time(hour, minute, second, millisecond)]; }; return Iterinfo; }()); /* harmony default export */ var iterinfo = (iterinfo_Iterinfo); //# sourceMappingURL=iterinfo.js.map // CONCATENATED MODULE: ./dist/esm/iterresult.js /** * This class helps us to emulate python's generators, sorta. */ var IterResult = /** @class */ (function () { function IterResult(method, args) { this.minDate = null; this.maxDate = null; this._result = []; this.total = 0; this.method = method; this.args = args; if (method === 'between') { this.maxDate = args.inc ? args.before : new Date(args.before.getTime() - 1); this.minDate = args.inc ? args.after : new Date(args.after.getTime() + 1); } else if (method === 'before') { this.maxDate = args.inc ? args.dt : new Date(args.dt.getTime() - 1); } else if (method === 'after') { this.minDate = args.inc ? args.dt : new Date(args.dt.getTime() + 1); } } /** * Possibly adds a date into the result. * * @param {Date} date - the date isn't necessarly added to the result * list (if it is too late/too early) * @return {Boolean} true if it makes sense to continue the iteration * false if we're done. */ IterResult.prototype.accept = function (date) { ++this.total; var tooEarly = this.minDate && date < this.minDate; var tooLate = this.maxDate && date > this.maxDate; if (this.method === 'between') { if (tooEarly) return true; if (tooLate) return false; } else if (this.method === 'before') { if (tooLate) return false; } else if (this.method === 'after') { if (tooEarly) return true; this.add(date); return false; } return this.add(date); }; /** * * @param {Date} date that is part of the result. * @return {Boolean} whether we are interested in more values. */ IterResult.prototype.add = function (date) { this._result.push(date); return true; }; /** * 'before' and 'after' return only one date, whereas 'all' * and 'between' an array. * @return {Date,Array?} */ IterResult.prototype.getValue = function () { var res = this._result; switch (this.method) { case 'all': case 'between': return res; case 'before': case 'after': return res.length ? res[res.length - 1] : null; } }; IterResult.prototype.clone = function () { return new IterResult(this.method, this.args); }; return IterResult; }()); /* harmony default export */ var iterresult = (IterResult); //# sourceMappingURL=iterresult.js.map // CONCATENATED MODULE: ./dist/esm/callbackiterresult.js var callbackiterresult_extends = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * IterResult subclass that calls a callback function on each add, * and stops iterating when the callback returns false. */ var CallbackIterResult = /** @class */ (function (_super) { callbackiterresult_extends(CallbackIterResult, _super); function CallbackIterResult(method, args, iterator) { var _this = _super.call(this, method, args) || this; _this.iterator = iterator; return _this; } CallbackIterResult.prototype.add = function (date) { if (this.iterator(date, this._result.length)) { this._result.push(date); return true; } return false; }; return CallbackIterResult; }(iterresult)); /* harmony default export */ var callbackiterresult = (CallbackIterResult); //# sourceMappingURL=callbackiterresult.js.map // CONCATENATED MODULE: ./dist/esm/types.js var Frequency; (function (Frequency) { Frequency[Frequency["YEARLY"] = 0] = "YEARLY"; Frequency[Frequency["MONTHLY"] = 1] = "MONTHLY"; Frequency[Frequency["WEEKLY"] = 2] = "WEEKLY"; Frequency[Frequency["DAILY"] = 3] = "DAILY"; Frequency[Frequency["HOURLY"] = 4] = "HOURLY"; Frequency[Frequency["MINUTELY"] = 5] = "MINUTELY"; Frequency[Frequency["SECONDLY"] = 6] = "SECONDLY"; })(Frequency || (Frequency = {})); //# sourceMappingURL=types.js.map // CONCATENATED MODULE: ./dist/esm/weekday.js // ============================================================================= // Weekday // ============================================================================= var WDAYS = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']; var Weekday = /** @class */ (function () { function Weekday(weekday, n) { if (n === 0) throw new Error("Can't create weekday with n == 0"); this.weekday = weekday; this.n = n; } // __call__ - Cannot call the object directly, do it through // e.g. RRule.TH.nth(-1) instead, Weekday.prototype.nth = function (n) { return this.n === n ? this : new Weekday(this.weekday, n); }; // __eq__ Weekday.prototype.equals = function (other) { return this.weekday === other.weekday && this.n === other.n; }; // __repr__ Weekday.prototype.toString = function () { var s = WDAYS[this.weekday]; if (this.n) s = (this.n > 0 ? '+' : '') + String(this.n) + s; return s; }; Weekday.prototype.getJsWeekday = function () { return this.weekday === 6 ? 0 : this.weekday + 1; }; return Weekday; }()); //# sourceMappingURL=weekday.js.map // CONCATENATED MODULE: ./dist/esm/parseoptions.js function initializeOptions(options) { var invalid = []; var keys = Object.keys(options); var initializedOptions = {}; // Shallow copy for options and origOptions and check for invalid keys.forEach(function (key) { initializedOptions[key] = options[key]; if (!Object(helpers["c" /* includes */])(rrule_defaultKeys, key)) invalid.push(key); }); if (invalid.length) { throw new Error('Invalid options: ' + invalid.join(', ')); } return initializedOptions; } function parseOptions(options) { var opts = initializeOptions(options); var keys = Object.keys(options); // Merge in default options rrule_defaultKeys.forEach(function (key) { if (!Object(helpers["c" /* includes */])(keys, key) || !Object(helpers["f" /* isPresent */])(opts[key])) opts[key] = DEFAULT_OPTIONS[key]; }); if (Object(helpers["f" /* isPresent */])(opts.byeaster)) opts.freq = esm_rrule.YEARLY; if (!(Object(helpers["f" /* isPresent */])(opts.freq) && esm_rrule.FREQUENCIES[opts.freq])) { throw new Error("Invalid frequency: " + opts.freq + " " + options.freq); } if (!opts.dtstart) opts.dtstart = new Date(new Date().setMilliseconds(0)); var millisecondModulo = opts.dtstart.getTime() % 1000; if (!Object(helpers["f" /* isPresent */])(opts.wkst)) { opts.wkst = esm_rrule.MO.weekday; } else if (Object(helpers["e" /* isNumber */])(opts.wkst)) { // cool, just keep it like that } else { opts.wkst = opts.wkst.weekday; } if (Object(helpers["f" /* isPresent */])(opts.bysetpos)) { if (Object(helpers["e" /* isNumber */])(opts.bysetpos)) opts.bysetpos = [opts.bysetpos]; for (var i = 0; i < opts.bysetpos.length; i++) { var v = opts.bysetpos[i]; if (v === 0 || !(v >= -366 && v <= 366)) { throw new Error('bysetpos must be between 1 and 366,' + ' or between -366 and -1'); } } } if (!(Boolean(opts.byweekno) || Object(helpers["g" /* notEmpty */])(opts.byweekno) || Object(helpers["g" /* notEmpty */])(opts.byyearday) || Boolean(opts.bymonthday) || Object(helpers["g" /* notEmpty */])(opts.bymonthday) || Object(helpers["f" /* isPresent */])(opts.byweekday) || Object(helpers["f" /* isPresent */])(opts.byeaster))) { switch (opts.freq) { case esm_rrule.YEARLY: if (!opts.bymonth) opts.bymonth = opts.dtstart.getUTCMonth() + 1; opts.bymonthday = opts.dtstart.getUTCDate(); break; case esm_rrule.MONTHLY: opts.bymonthday = opts.dtstart.getUTCDate(); break; case esm_rrule.WEEKLY: opts.byweekday = [esm_dateutil.getWeekday(opts.dtstart)]; break; } } // bymonth if (Object(helpers["f" /* isPresent */])(opts.bymonth) && !Object(helpers["d" /* isArray */])(opts.bymonth)) { opts.bymonth = [opts.bymonth]; } // byyearday if (Object(helpers["f" /* isPresent */])(opts.byyearday) && !Object(helpers["d" /* isArray */])(opts.byyearday) && Object(helpers["e" /* isNumber */])(opts.byyearday)) { opts.byyearday = [opts.byyearday]; } // bymonthday if (!Object(helpers["f" /* isPresent */])(opts.bymonthday)) { opts.bymonthday = []; opts.bynmonthday = []; } else if (Object(helpers["d" /* isArray */])(opts.bymonthday)) { var bymonthday = []; var bynmonthday = []; for (var i = 0; i < opts.bymonthday.length; i++) { var v = opts.bymonthday[i]; if (v > 0) { bymonthday.push(v); } else if (v < 0) { bynmonthday.push(v); } } opts.bymonthday = bymonthday; opts.bynmonthday = bynmonthday; } else if (opts.bymonthday < 0) { opts.bynmonthday = [opts.bymonthday]; opts.bymonthday = []; } else { opts.bynmonthday = []; opts.bymonthday = [opts.bymonthday]; } // byweekno if (Object(helpers["f" /* isPresent */])(opts.byweekno) && !Object(helpers["d" /* isArray */])(opts.byweekno)) { opts.byweekno = [opts.byweekno]; } // byweekday / bynweekday if (!Object(helpers["f" /* isPresent */])(opts.byweekday)) { opts.bynweekday = null; } else if (Object(helpers["e" /* isNumber */])(opts.byweekday)) { opts.byweekday = [opts.byweekday]; opts.bynweekday = null; } else if (opts.byweekday instanceof Weekday) { if (!opts.byweekday.n || opts.freq > esm_rrule.MONTHLY) { opts.byweekday = [opts.byweekday.weekday]; opts.bynweekday = null; } else { opts.bynweekday = [[opts.byweekday.weekday, opts.byweekday.n]]; opts.byweekday = null; } } else { var byweekday = []; var bynweekday = []; for (var i = 0; i < opts.byweekday.length; i++) { var wday = opts.byweekday[i]; if (Object(helpers["e" /* isNumber */])(wday)) { byweekday.push(wday); continue; } var wd = wday; if (!wd.n || opts.freq > esm_rrule.MONTHLY) { byweekday.push(wd.weekday); } else { bynweekday.push([wd.weekday, wd.n]); } } opts.byweekday = Object(helpers["g" /* notEmpty */])(byweekday) ? byweekday : null; opts.bynweekday = Object(helpers["g" /* notEmpty */])(bynweekday) ? bynweekday : null; } // byhour if (!Object(helpers["f" /* isPresent */])(opts.byhour)) { opts.byhour = opts.freq < esm_rrule.HOURLY ? [opts.dtstart.getUTCHours()] : null; } else if (Object(helpers["e" /* isNumber */])(opts.byhour)) { opts.byhour = [opts.byhour]; } // byminute if (!Object(helpers["f" /* isPresent */])(opts.byminute)) { opts.byminute = opts.freq < esm_rrule.MINUTELY ? [opts.dtstart.getUTCMinutes()] : null; } else if (Object(helpers["e" /* isNumber */])(opts.byminute)) { opts.byminute = [opts.byminute]; } // bysecond if (!Object(helpers["f" /* isPresent */])(opts.bysecond)) { opts.bysecond = opts.freq < esm_rrule.SECONDLY ? [opts.dtstart.getUTCSeconds()] : null; } else if (Object(helpers["e" /* isNumber */])(opts.bysecond)) { opts.bysecond = [opts.bysecond]; } var timeset; if (opts.freq >= esm_rrule.HOURLY) { timeset = null; } else { timeset = []; for (var i = 0; i < opts.byhour.length; i++) { var hour = opts.byhour[i]; for (var j = 0; j < opts.byminute.length; j++) { var minute = opts.byminute[j]; for (var k = 0; k < opts.bysecond.length; k++) { var second = opts.bysecond[k]; // python: // datetime.time(hour, minute, second, // tzinfo=self._tzinfo)) timeset.push(new esm_dateutil.Time(hour, minute, se