Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rrule.js 126KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["rrule"] = factory();
  8. else
  9. root["rrule"] = factory();
  10. })(typeof self !== 'undefined' ? self : this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = 0);
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ([
  98. /* 0 */
  99. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  100. "use strict";
  101. __webpack_require__.r(__webpack_exports__);
  102. // CONCATENATED MODULE: ./src/weekday.ts
  103. // =============================================================================
  104. // Weekday
  105. // =============================================================================
  106. var ALL_WEEKDAYS = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'];
  107. var Weekday = /** @class */ (function () {
  108. function Weekday(weekday, n) {
  109. if (n === 0)
  110. throw new Error("Can't create weekday with n == 0");
  111. this.weekday = weekday;
  112. this.n = n;
  113. }
  114. Weekday.fromStr = function (str) {
  115. return new Weekday(ALL_WEEKDAYS.indexOf(str));
  116. };
  117. // __call__ - Cannot call the object directly, do it through
  118. // e.g. RRule.TH.nth(-1) instead,
  119. Weekday.prototype.nth = function (n) {
  120. return this.n === n ? this : new Weekday(this.weekday, n);
  121. };
  122. // __eq__
  123. Weekday.prototype.equals = function (other) {
  124. return this.weekday === other.weekday && this.n === other.n;
  125. };
  126. // __repr__
  127. Weekday.prototype.toString = function () {
  128. var s = ALL_WEEKDAYS[this.weekday];
  129. if (this.n)
  130. s = (this.n > 0 ? '+' : '') + String(this.n) + s;
  131. return s;
  132. };
  133. Weekday.prototype.getJsWeekday = function () {
  134. return this.weekday === 6 ? 0 : this.weekday + 1;
  135. };
  136. return Weekday;
  137. }());
  138. // CONCATENATED MODULE: ./src/helpers.ts
  139. // =============================================================================
  140. // Helper functions
  141. // =============================================================================
  142. var isPresent = function (value) {
  143. return value !== null && value !== undefined;
  144. };
  145. var isNumber = function (value) {
  146. return typeof value === 'number';
  147. };
  148. var isWeekdayStr = function (value) {
  149. return ALL_WEEKDAYS.indexOf(value) >= 0;
  150. };
  151. var isArray = Array.isArray;
  152. /**
  153. * Simplified version of python's range()
  154. */
  155. var range = function (start, end) {
  156. if (end === void 0) { end = start; }
  157. if (arguments.length === 1) {
  158. end = start;
  159. start = 0;
  160. }
  161. var rang = [];
  162. for (var i = start; i < end; i++)
  163. rang.push(i);
  164. return rang;
  165. };
  166. var clone = function (array) {
  167. return [].concat(array);
  168. };
  169. var repeat = function (value, times) {
  170. var i = 0;
  171. var array = [];
  172. if (isArray(value)) {
  173. for (; i < times; i++)
  174. array[i] = [].concat(value);
  175. }
  176. else {
  177. for (; i < times; i++)
  178. array[i] = value;
  179. }
  180. return array;
  181. };
  182. var toArray = function (item) {
  183. if (isArray(item)) {
  184. return item;
  185. }
  186. return [item];
  187. };
  188. function padStart(item, targetLength, padString) {
  189. if (padString === void 0) { padString = ' '; }
  190. var str = String(item);
  191. targetLength = targetLength >> 0;
  192. if (str.length > targetLength) {
  193. return String(str);
  194. }
  195. targetLength = targetLength - str.length;
  196. if (targetLength > padString.length) {
  197. padString += repeat(padString, targetLength / padString.length);
  198. }
  199. return padString.slice(0, targetLength) + String(str);
  200. }
  201. /**
  202. * Python like split
  203. */
  204. var split = function (str, sep, num) {
  205. var splits = str.split(sep);
  206. return num
  207. ? splits.slice(0, num).concat([splits.slice(num).join(sep)])
  208. : splits;
  209. };
  210. /**
  211. * closure/goog/math/math.js:modulo
  212. * Copyright 2006 The Closure Library Authors.
  213. * The % operator in JavaScript returns the remainder of a / b, but differs from
  214. * some other languages in that the result will have the same sign as the
  215. * dividend. For example, -1 % 8 == -1, whereas in some other languages
  216. * (such as Python) the result would be 7. This function emulates the more
  217. * correct modulo behavior, which is useful for certain applications such as
  218. * calculating an offset index in a circular list.
  219. *
  220. * @param {number} a The dividend.
  221. * @param {number} b The divisor.
  222. * @return {number} a % b where the result is between 0 and b (either 0 <= x < b
  223. * or b < x <= 0, depending on the sign of b).
  224. */
  225. var pymod = function (a, b) {
  226. var r = a % b;
  227. // If r and b differ in sign, add b to wrap the result to the correct sign.
  228. return r * b < 0 ? r + b : r;
  229. };
  230. /**
  231. * @see: <http://docs.python.org/library/functions.html#divmod>
  232. */
  233. var divmod = function (a, b) {
  234. return { div: Math.floor(a / b), mod: pymod(a, b) };
  235. };
  236. var empty = function (obj) {
  237. return !isPresent(obj) || obj.length === 0;
  238. };
  239. /**
  240. * Python-like boolean
  241. * @return {Boolean} value of an object/primitive, taking into account
  242. * the fact that in Python an empty list's/tuple's
  243. * boolean value is False, whereas in JS it's true
  244. */
  245. var notEmpty = function (obj) {
  246. return !empty(obj);
  247. };
  248. /**
  249. * Return true if a value is in an array
  250. */
  251. var includes = function (arr, val) {
  252. return notEmpty(arr) && arr.indexOf(val) !== -1;
  253. };
  254. // CONCATENATED MODULE: ./src/dateutil.ts
  255. /**
  256. * General date-related utilities.
  257. * Also handles several incompatibilities between JavaScript and Python
  258. *
  259. */
  260. var dateutil_dateutil;
  261. (function (dateutil) {
  262. dateutil.MONTH_DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  263. /**
  264. * Number of milliseconds of one day
  265. */
  266. dateutil.ONE_DAY = 1000 * 60 * 60 * 24;
  267. /**
  268. * @see: <http://docs.python.org/library/datetime.html#datetime.MAXYEAR>
  269. */
  270. dateutil.MAXYEAR = 9999;
  271. /**
  272. * Python uses 1-Jan-1 as the base for calculating ordinals but we don't
  273. * want to confuse the JS engine with milliseconds > Number.MAX_NUMBER,
  274. * therefore we use 1-Jan-1970 instead
  275. */
  276. dateutil.ORDINAL_BASE = new Date(Date.UTC(1970, 0, 1));
  277. /**
  278. * Python: MO-SU: 0 - 6
  279. * JS: SU-SAT 0 - 6
  280. */
  281. dateutil.PY_WEEKDAYS = [6, 0, 1, 2, 3, 4, 5];
  282. /**
  283. * py_date.timetuple()[7]
  284. */
  285. dateutil.getYearDay = function (date) {
  286. var dateNoTime = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
  287. return (Math.ceil((dateNoTime.valueOf() -
  288. new Date(date.getUTCFullYear(), 0, 1).valueOf()) /
  289. dateutil.ONE_DAY) + 1);
  290. };
  291. dateutil.isLeapYear = function (year) {
  292. return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  293. };
  294. dateutil.isDate = function (value) {
  295. return value instanceof Date;
  296. };
  297. dateutil.isValidDate = function (value) {
  298. return dateutil.isDate(value) && !isNaN(value.getTime());
  299. };
  300. /**
  301. * @return {Number} the date's timezone offset in ms
  302. */
  303. dateutil.tzOffset = function (date) {
  304. return date.getTimezoneOffset() * 60 * 1000;
  305. };
  306. /**
  307. * @see: <http://www.mcfedries.com/JavaScript/DaysBetween.asp>
  308. */
  309. dateutil.daysBetween = function (date1, date2) {
  310. // The number of milliseconds in one day
  311. // Convert both dates to milliseconds
  312. var date1ms = date1.getTime() - dateutil.tzOffset(date1);
  313. var date2ms = date2.getTime() - dateutil.tzOffset(date2);
  314. // Calculate the difference in milliseconds
  315. var differencems = date1ms - date2ms;
  316. // Convert back to days and return
  317. return Math.round(differencems / dateutil.ONE_DAY);
  318. };
  319. /**
  320. * @see: <http://docs.python.org/library/datetime.html#datetime.date.toordinal>
  321. */
  322. dateutil.toOrdinal = function (date) {
  323. return dateutil.daysBetween(date, dateutil.ORDINAL_BASE);
  324. };
  325. /**
  326. * @see - <http://docs.python.org/library/datetime.html#datetime.date.fromordinal>
  327. */
  328. dateutil.fromOrdinal = function (ordinal) {
  329. return new Date(dateutil.ORDINAL_BASE.getTime() + ordinal * dateutil.ONE_DAY);
  330. };
  331. dateutil.getMonthDays = function (date) {
  332. var month = date.getUTCMonth();
  333. return month === 1 && dateutil.isLeapYear(date.getUTCFullYear())
  334. ? 29
  335. : dateutil.MONTH_DAYS[month];
  336. };
  337. /**
  338. * @return {Number} python-like weekday
  339. */
  340. dateutil.getWeekday = function (date) {
  341. return dateutil.PY_WEEKDAYS[date.getUTCDay()];
  342. };
  343. /**
  344. * @see: <http://docs.python.org/library/calendar.html#calendar.monthrange>
  345. */
  346. dateutil.monthRange = function (year, month) {
  347. var date = new Date(Date.UTC(year, month, 1));
  348. return [dateutil.getWeekday(date), dateutil.getMonthDays(date)];
  349. };
  350. /**
  351. * @see: <http://docs.python.org/library/datetime.html#datetime.datetime.combine>
  352. */
  353. dateutil.combine = function (date, time) {
  354. time = time || date;
  355. return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), time.getHours(), time.getMinutes(), time.getSeconds(), time.getMilliseconds()));
  356. };
  357. dateutil.clone = function (date) {
  358. var dolly = new Date(date.getTime());
  359. return dolly;
  360. };
  361. dateutil.cloneDates = function (dates) {
  362. var clones = [];
  363. for (var i = 0; i < dates.length; i++) {
  364. clones.push(dateutil.clone(dates[i]));
  365. }
  366. return clones;
  367. };
  368. /**
  369. * Sorts an array of Date or dateutil.Time objects
  370. */
  371. dateutil.sort = function (dates) {
  372. dates.sort(function (a, b) {
  373. return a.getTime() - b.getTime();
  374. });
  375. };
  376. dateutil.timeToUntilString = function (time, utc) {
  377. if (utc === void 0) { utc = true; }
  378. var date = new Date(time);
  379. return [
  380. padStart(date.getUTCFullYear().toString(), 4, '0'),
  381. padStart(date.getUTCMonth() + 1, 2, '0'),
  382. padStart(date.getUTCDate(), 2, '0'),
  383. 'T',
  384. padStart(date.getUTCHours(), 2, '0'),
  385. padStart(date.getUTCMinutes(), 2, '0'),
  386. padStart(date.getUTCSeconds(), 2, '0'),
  387. utc ? 'Z' : ''
  388. ].join('');
  389. };
  390. dateutil.untilStringToDate = function (until) {
  391. var re = /^(\d{4})(\d{2})(\d{2})(T(\d{2})(\d{2})(\d{2})Z?)?$/;
  392. var bits = re.exec(until);
  393. if (!bits)
  394. throw new Error("Invalid UNTIL value: " + until);
  395. 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));
  396. };
  397. })(dateutil_dateutil || (dateutil_dateutil = {}));
  398. /* harmony default export */ var src_dateutil = (dateutil_dateutil);
  399. // CONCATENATED MODULE: ./src/iterresult.ts
  400. /**
  401. * This class helps us to emulate python's generators, sorta.
  402. */
  403. var IterResult = /** @class */ (function () {
  404. function IterResult(method, args) {
  405. this.minDate = null;
  406. this.maxDate = null;
  407. this._result = [];
  408. this.total = 0;
  409. this.method = method;
  410. this.args = args;
  411. if (method === 'between') {
  412. this.maxDate = args.inc
  413. ? args.before
  414. : new Date(args.before.getTime() - 1);
  415. this.minDate = args.inc ? args.after : new Date(args.after.getTime() + 1);
  416. }
  417. else if (method === 'before') {
  418. this.maxDate = args.inc ? args.dt : new Date(args.dt.getTime() - 1);
  419. }
  420. else if (method === 'after') {
  421. this.minDate = args.inc ? args.dt : new Date(args.dt.getTime() + 1);
  422. }
  423. }
  424. /**
  425. * Possibly adds a date into the result.
  426. *
  427. * @param {Date} date - the date isn't necessarly added to the result
  428. * list (if it is too late/too early)
  429. * @return {Boolean} true if it makes sense to continue the iteration
  430. * false if we're done.
  431. */
  432. IterResult.prototype.accept = function (date) {
  433. ++this.total;
  434. var tooEarly = this.minDate && date < this.minDate;
  435. var tooLate = this.maxDate && date > this.maxDate;
  436. if (this.method === 'between') {
  437. if (tooEarly)
  438. return true;
  439. if (tooLate)
  440. return false;
  441. }
  442. else if (this.method === 'before') {
  443. if (tooLate)
  444. return false;
  445. }
  446. else if (this.method === 'after') {
  447. if (tooEarly)
  448. return true;
  449. this.add(date);
  450. return false;
  451. }
  452. return this.add(date);
  453. };
  454. /**
  455. *
  456. * @param {Date} date that is part of the result.
  457. * @return {Boolean} whether we are interested in more values.
  458. */
  459. IterResult.prototype.add = function (date) {
  460. this._result.push(date);
  461. return true;
  462. };
  463. /**
  464. * 'before' and 'after' return only one date, whereas 'all'
  465. * and 'between' an array.
  466. * @return {Date,Array?}
  467. */
  468. IterResult.prototype.getValue = function () {
  469. var res = this._result;
  470. switch (this.method) {
  471. case 'all':
  472. case 'between':
  473. return res;
  474. case 'before':
  475. case 'after':
  476. default:
  477. return (res.length ? res[res.length - 1] : null);
  478. }
  479. };
  480. IterResult.prototype.clone = function () {
  481. return new IterResult(this.method, this.args);
  482. };
  483. return IterResult;
  484. }());
  485. /* harmony default export */ var iterresult = (IterResult);
  486. // CONCATENATED MODULE: ./node_modules/tslib/tslib.es6.js
  487. /*! *****************************************************************************
  488. Copyright (c) Microsoft Corporation. All rights reserved.
  489. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  490. this file except in compliance with the License. You may obtain a copy of the
  491. License at http://www.apache.org/licenses/LICENSE-2.0
  492. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  493. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  494. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  495. MERCHANTABLITY OR NON-INFRINGEMENT.
  496. See the Apache Version 2.0 License for specific language governing permissions
  497. and limitations under the License.
  498. ***************************************************************************** */
  499. /* global Reflect, Promise */
  500. var extendStatics = function(d, b) {
  501. extendStatics = Object.setPrototypeOf ||
  502. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  503. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  504. return extendStatics(d, b);
  505. };
  506. function __extends(d, b) {
  507. extendStatics(d, b);
  508. function __() { this.constructor = d; }
  509. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  510. }
  511. var __assign = function() {
  512. __assign = Object.assign || function __assign(t) {
  513. for (var s, i = 1, n = arguments.length; i < n; i++) {
  514. s = arguments[i];
  515. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  516. }
  517. return t;
  518. }
  519. return __assign.apply(this, arguments);
  520. }
  521. function __rest(s, e) {
  522. var t = {};
  523. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  524. t[p] = s[p];
  525. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  526. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  527. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  528. t[p[i]] = s[p[i]];
  529. }
  530. return t;
  531. }
  532. function __decorate(decorators, target, key, desc) {
  533. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  534. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  535. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  536. return c > 3 && r && Object.defineProperty(target, key, r), r;
  537. }
  538. function __param(paramIndex, decorator) {
  539. return function (target, key) { decorator(target, key, paramIndex); }
  540. }
  541. function __metadata(metadataKey, metadataValue) {
  542. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  543. }
  544. function __awaiter(thisArg, _arguments, P, generator) {
  545. return new (P || (P = Promise))(function (resolve, reject) {
  546. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  547. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  548. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  549. step((generator = generator.apply(thisArg, _arguments || [])).next());
  550. });
  551. }
  552. function __generator(thisArg, body) {
  553. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  554. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  555. function verb(n) { return function (v) { return step([n, v]); }; }
  556. function step(op) {
  557. if (f) throw new TypeError("Generator is already executing.");
  558. while (_) try {
  559. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  560. if (y = 0, t) op = [op[0] & 2, t.value];
  561. switch (op[0]) {
  562. case 0: case 1: t = op; break;
  563. case 4: _.label++; return { value: op[1], done: false };
  564. case 5: _.label++; y = op[1]; op = [0]; continue;
  565. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  566. default:
  567. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  568. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  569. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  570. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  571. if (t[2]) _.ops.pop();
  572. _.trys.pop(); continue;
  573. }
  574. op = body.call(thisArg, _);
  575. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  576. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  577. }
  578. }
  579. function __exportStar(m, exports) {
  580. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  581. }
  582. function __values(o) {
  583. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  584. if (m) return m.call(o);
  585. return {
  586. next: function () {
  587. if (o && i >= o.length) o = void 0;
  588. return { value: o && o[i++], done: !o };
  589. }
  590. };
  591. }
  592. function __read(o, n) {
  593. var m = typeof Symbol === "function" && o[Symbol.iterator];
  594. if (!m) return o;
  595. var i = m.call(o), r, ar = [], e;
  596. try {
  597. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  598. }
  599. catch (error) { e = { error: error }; }
  600. finally {
  601. try {
  602. if (r && !r.done && (m = i["return"])) m.call(i);
  603. }
  604. finally { if (e) throw e.error; }
  605. }
  606. return ar;
  607. }
  608. function __spread() {
  609. for (var ar = [], i = 0; i < arguments.length; i++)
  610. ar = ar.concat(__read(arguments[i]));
  611. return ar;
  612. }
  613. function __spreadArrays() {
  614. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  615. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  616. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  617. r[k] = a[j];
  618. return r;
  619. };
  620. function __await(v) {
  621. return this instanceof __await ? (this.v = v, this) : new __await(v);
  622. }
  623. function __asyncGenerator(thisArg, _arguments, generator) {
  624. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  625. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  626. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  627. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  628. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  629. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  630. function fulfill(value) { resume("next", value); }
  631. function reject(value) { resume("throw", value); }
  632. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  633. }
  634. function __asyncDelegator(o) {
  635. var i, p;
  636. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  637. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  638. }
  639. function __asyncValues(o) {
  640. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  641. var m = o[Symbol.asyncIterator], i;
  642. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  643. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  644. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  645. }
  646. function __makeTemplateObject(cooked, raw) {
  647. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  648. return cooked;
  649. };
  650. function __importStar(mod) {
  651. if (mod && mod.__esModule) return mod;
  652. var result = {};
  653. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  654. result.default = mod;
  655. return result;
  656. }
  657. function __importDefault(mod) {
  658. return (mod && mod.__esModule) ? mod : { default: mod };
  659. }
  660. // CONCATENATED MODULE: ./src/callbackiterresult.ts
  661. /**
  662. * IterResult subclass that calls a callback function on each add,
  663. * and stops iterating when the callback returns false.
  664. */
  665. var callbackiterresult_CallbackIterResult = /** @class */ (function (_super) {
  666. __extends(CallbackIterResult, _super);
  667. function CallbackIterResult(method, args, iterator) {
  668. var _this = _super.call(this, method, args) || this;
  669. _this.iterator = iterator;
  670. return _this;
  671. }
  672. CallbackIterResult.prototype.add = function (date) {
  673. if (this.iterator(date, this._result.length)) {
  674. this._result.push(date);
  675. return true;
  676. }
  677. return false;
  678. };
  679. return CallbackIterResult;
  680. }(iterresult));
  681. /* harmony default export */ var callbackiterresult = (callbackiterresult_CallbackIterResult);
  682. // CONCATENATED MODULE: ./src/nlp/i18n.ts
  683. // =============================================================================
  684. // i18n
  685. // =============================================================================
  686. var ENGLISH = {
  687. dayNames: [
  688. 'Sunday', 'Monday', 'Tuesday', 'Wednesday',
  689. 'Thursday', 'Friday', 'Saturday'
  690. ],
  691. monthNames: [
  692. 'January', 'February', 'March', 'April', 'May',
  693. 'June', 'July', 'August', 'September', 'October',
  694. 'November', 'December'
  695. ],
  696. tokens: {
  697. 'SKIP': /^[ \r\n\t]+|^\.$/,
  698. 'number': /^[1-9][0-9]*/,
  699. 'numberAsText': /^(one|two|three)/i,
  700. 'every': /^every/i,
  701. 'day(s)': /^days?/i,
  702. 'weekday(s)': /^weekdays?/i,
  703. 'week(s)': /^weeks?/i,
  704. 'hour(s)': /^hours?/i,
  705. 'minute(s)': /^minutes?/i,
  706. 'month(s)': /^months?/i,
  707. 'year(s)': /^years?/i,
  708. 'on': /^(on|in)/i,
  709. 'at': /^(at)/i,
  710. 'the': /^the/i,
  711. 'first': /^first/i,
  712. 'second': /^second/i,
  713. 'third': /^third/i,
  714. 'nth': /^([1-9][0-9]*)(\.|th|nd|rd|st)/i,
  715. 'last': /^last/i,
  716. 'for': /^for/i,
  717. 'time(s)': /^times?/i,
  718. 'until': /^(un)?til/i,
  719. 'monday': /^mo(n(day)?)?/i,
  720. 'tuesday': /^tu(e(s(day)?)?)?/i,
  721. 'wednesday': /^we(d(n(esday)?)?)?/i,
  722. 'thursday': /^th(u(r(sday)?)?)?/i,
  723. 'friday': /^fr(i(day)?)?/i,
  724. 'saturday': /^sa(t(urday)?)?/i,
  725. 'sunday': /^su(n(day)?)?/i,
  726. 'january': /^jan(uary)?/i,
  727. 'february': /^feb(ruary)?/i,
  728. 'march': /^mar(ch)?/i,
  729. 'april': /^apr(il)?/i,
  730. 'may': /^may/i,
  731. 'june': /^june?/i,
  732. 'july': /^july?/i,
  733. 'august': /^aug(ust)?/i,
  734. 'september': /^sep(t(ember)?)?/i,
  735. 'october': /^oct(ober)?/i,
  736. 'november': /^nov(ember)?/i,
  737. 'december': /^dec(ember)?/i,
  738. 'comma': /^(,\s*|(and|or)\s*)+/i
  739. }
  740. };
  741. /* harmony default export */ var i18n = (ENGLISH);
  742. // CONCATENATED MODULE: ./src/nlp/totext.ts
  743. // =============================================================================
  744. // Helper functions
  745. // =============================================================================
  746. /**
  747. * Return true if a value is in an array
  748. */
  749. var contains = function (arr, val) {
  750. return arr.indexOf(val) !== -1;
  751. };
  752. var defaultGetText = function (id) { return id.toString(); };
  753. var defaultDateFormatter = function (year, month, day) { return month + " " + day + ", " + year; };
  754. /**
  755. *
  756. * @param {RRule} rrule
  757. * Optional:
  758. * @param {Function} gettext function
  759. * @param {Object} language definition
  760. * @constructor
  761. */
  762. var totext_ToText = /** @class */ (function () {
  763. function ToText(rrule, gettext, language, dateFormatter) {
  764. if (gettext === void 0) { gettext = defaultGetText; }
  765. if (language === void 0) { language = i18n; }
  766. if (dateFormatter === void 0) { dateFormatter = defaultDateFormatter; }
  767. this.text = [];
  768. this.language = language || i18n;
  769. this.gettext = gettext;
  770. this.dateFormatter = dateFormatter;
  771. this.rrule = rrule;
  772. this.options = rrule.options;
  773. this.origOptions = rrule.origOptions;
  774. if (this.origOptions.bymonthday) {
  775. var bymonthday = [].concat(this.options.bymonthday);
  776. var bynmonthday = [].concat(this.options.bynmonthday);
  777. bymonthday.sort(function (a, b) { return a - b; });
  778. bynmonthday.sort(function (a, b) { return b - a; });
  779. // 1, 2, 3, .., -5, -4, -3, ..
  780. this.bymonthday = bymonthday.concat(bynmonthday);
  781. if (!this.bymonthday.length)
  782. this.bymonthday = null;
  783. }
  784. if (isPresent(this.origOptions.byweekday)) {
  785. var byweekday = !isArray(this.origOptions.byweekday)
  786. ? [this.origOptions.byweekday]
  787. : this.origOptions.byweekday;
  788. var days = String(byweekday);
  789. this.byweekday = {
  790. allWeeks: byweekday.filter(function (weekday) {
  791. return !weekday.n;
  792. }),
  793. someWeeks: byweekday.filter(function (weekday) {
  794. return Boolean(weekday.n);
  795. }),
  796. isWeekdays: days.indexOf('MO') !== -1 &&
  797. days.indexOf('TU') !== -1 &&
  798. days.indexOf('WE') !== -1 &&
  799. days.indexOf('TH') !== -1 &&
  800. days.indexOf('FR') !== -1 &&
  801. days.indexOf('SA') === -1 &&
  802. days.indexOf('SU') === -1,
  803. isEveryDay: days.indexOf('MO') !== -1 &&
  804. days.indexOf('TU') !== -1 &&
  805. days.indexOf('WE') !== -1 &&
  806. days.indexOf('TH') !== -1 &&
  807. days.indexOf('FR') !== -1 &&
  808. days.indexOf('SA') !== -1 &&
  809. days.indexOf('SU') !== -1
  810. };
  811. var sortWeekDays = function (a, b) {
  812. return a.weekday - b.weekday;
  813. };
  814. this.byweekday.allWeeks.sort(sortWeekDays);
  815. this.byweekday.someWeeks.sort(sortWeekDays);
  816. if (!this.byweekday.allWeeks.length)
  817. this.byweekday.allWeeks = null;
  818. if (!this.byweekday.someWeeks.length)
  819. this.byweekday.someWeeks = null;
  820. }
  821. else {
  822. this.byweekday = null;
  823. }
  824. }
  825. /**
  826. * Test whether the rrule can be fully converted to text.
  827. * @param {RRule} rrule
  828. * @return {Boolean}
  829. */
  830. ToText.isFullyConvertible = function (rrule) {
  831. var canConvert = true;
  832. if (!(rrule.options.freq in ToText.IMPLEMENTED))
  833. return false;
  834. if (rrule.origOptions.until && rrule.origOptions.count)
  835. return false;
  836. for (var key in rrule.origOptions) {
  837. if (contains(['dtstart', 'wkst', 'freq'], key))
  838. return true;
  839. if (!contains(ToText.IMPLEMENTED[rrule.options.freq], key))
  840. return false;
  841. }
  842. return canConvert;
  843. };
  844. ToText.prototype.isFullyConvertible = function () {
  845. return ToText.isFullyConvertible(this.rrule);
  846. };
  847. /**
  848. * Perform the conversion. Only some of the frequencies are supported.
  849. * If some of the rrule's options aren't supported, they'll
  850. * be omitted from the output an "(~ approximate)" will be appended.
  851. * @return {*}
  852. */
  853. ToText.prototype.toString = function () {
  854. var gettext = this.gettext;
  855. if (!(this.options.freq in ToText.IMPLEMENTED)) {
  856. return gettext('RRule error: Unable to fully convert this rrule to text');
  857. }
  858. this.text = [gettext('every')];
  859. // @ts-ignore
  860. this[src.FREQUENCIES[this.options.freq]]();
  861. if (this.options.until) {
  862. this.add(gettext('until'));
  863. var until = this.options.until;
  864. this.add(this.dateFormatter(until.getUTCFullYear(), this.language.monthNames[until.getUTCMonth()], until.getUTCDate()));
  865. }
  866. else if (this.options.count) {
  867. this.add(gettext('for'))
  868. .add(this.options.count.toString())
  869. .add(this.plural(this.options.count) ? gettext('times') : gettext('time'));
  870. }
  871. if (!this.isFullyConvertible())
  872. this.add(gettext('(~ approximate)'));
  873. return this.text.join('');
  874. };
  875. ToText.prototype.HOURLY = function () {
  876. var gettext = this.gettext;
  877. if (this.options.interval !== 1)
  878. this.add(this.options.interval.toString());
  879. this.add(this.plural(this.options.interval) ? gettext('hours') : gettext('hour'));
  880. };
  881. ToText.prototype.MINUTELY = function () {
  882. var gettext = this.gettext;
  883. if (this.options.interval !== 1)
  884. this.add(this.options.interval.toString());
  885. this.add(this.plural(this.options.interval)
  886. ? gettext('minutes')
  887. : gettext('minute'));
  888. };
  889. ToText.prototype.DAILY = function () {
  890. var gettext = this.gettext;
  891. if (this.options.interval !== 1)
  892. this.add(this.options.interval.toString());
  893. if (this.byweekday && this.byweekday.isWeekdays) {
  894. this.add(this.plural(this.options.interval)
  895. ? gettext('weekdays')
  896. : gettext('weekday'));
  897. }
  898. else {
  899. this.add(this.plural(this.options.interval) ? gettext('days') : gettext('day'));
  900. }
  901. if (this.origOptions.bymonth) {
  902. this.add(gettext('in'));
  903. this._bymonth();
  904. }
  905. if (this.bymonthday) {
  906. this._bymonthday();
  907. }
  908. else if (this.byweekday) {
  909. this._byweekday();
  910. }
  911. else if (this.origOptions.byhour) {
  912. this._byhour();
  913. }
  914. };
  915. ToText.prototype.WEEKLY = function () {
  916. var gettext = this.gettext;
  917. if (this.options.interval !== 1) {
  918. this.add(this.options.interval.toString()).add(this.plural(this.options.interval) ? gettext('weeks') : gettext('week'));
  919. }
  920. if (this.byweekday && this.byweekday.isWeekdays) {
  921. if (this.options.interval === 1) {
  922. this.add(this.plural(this.options.interval)
  923. ? gettext('weekdays')
  924. : gettext('weekday'));
  925. }
  926. else {
  927. this.add(gettext('on')).add(gettext('weekdays'));
  928. }
  929. }
  930. else if (this.byweekday && this.byweekday.isEveryDay) {
  931. this.add(this.plural(this.options.interval) ? gettext('days') : gettext('day'));
  932. }
  933. else {
  934. if (this.options.interval === 1)
  935. this.add(gettext('week'));
  936. if (this.origOptions.bymonth) {
  937. this.add(gettext('in'));
  938. this._bymonth();
  939. }
  940. if (this.bymonthday) {
  941. this._bymonthday();
  942. }
  943. else if (this.byweekday) {
  944. this._byweekday();
  945. }
  946. }
  947. };
  948. ToText.prototype.MONTHLY = function () {
  949. var gettext = this.gettext;
  950. if (this.origOptions.bymonth) {
  951. if (this.options.interval !== 1) {
  952. this.add(this.options.interval.toString()).add(gettext('months'));
  953. if (this.plural(this.options.interval))
  954. this.add(gettext('in'));
  955. }
  956. else {
  957. // this.add(gettext('MONTH'))
  958. }
  959. this._bymonth();
  960. }
  961. else {
  962. if (this.options.interval !== 1)
  963. this.add(this.options.interval.toString());
  964. this.add(this.plural(this.options.interval)
  965. ? gettext('months')
  966. : gettext('month'));
  967. }
  968. if (this.bymonthday) {
  969. this._bymonthday();
  970. }
  971. else if (this.byweekday && this.byweekday.isWeekdays) {
  972. this.add(gettext('on')).add(gettext('weekdays'));
  973. }
  974. else if (this.byweekday) {
  975. this._byweekday();
  976. }
  977. };
  978. ToText.prototype.YEARLY = function () {
  979. var gettext = this.gettext;
  980. if (this.origOptions.bymonth) {
  981. if (this.options.interval !== 1) {
  982. this.add(this.options.interval.toString());
  983. this.add(gettext('years'));
  984. }
  985. else {
  986. // this.add(gettext('YEAR'))
  987. }
  988. this._bymonth();
  989. }
  990. else {
  991. if (this.options.interval !== 1)
  992. this.add(this.options.interval.toString());
  993. this.add(this.plural(this.options.interval) ? gettext('years') : gettext('year'));
  994. }
  995. if (this.bymonthday) {
  996. this._bymonthday();
  997. }
  998. else if (this.byweekday) {
  999. this._byweekday();
  1000. }
  1001. if (this.options.byyearday) {
  1002. this.add(gettext('on the'))
  1003. .add(this.list(this.options.byyearday, this.nth, gettext('and')))
  1004. .add(gettext('day'));
  1005. }
  1006. if (this.options.byweekno) {
  1007. this.add(gettext('in'))
  1008. .add(this.plural(this.options.byweekno.length)
  1009. ? gettext('weeks')
  1010. : gettext('week'))
  1011. .add(this.list(this.options.byweekno, undefined, gettext('and')));
  1012. }
  1013. };
  1014. ToText.prototype._bymonthday = function () {
  1015. var gettext = this.gettext;
  1016. if (this.byweekday && this.byweekday.allWeeks) {
  1017. this.add(gettext('on'))
  1018. .add(this.list(this.byweekday.allWeeks, this.weekdaytext, gettext('or')))
  1019. .add(gettext('the'))
  1020. .add(this.list(this.bymonthday, this.nth, gettext('or')));
  1021. }
  1022. else {
  1023. this.add(gettext('on the')).add(this.list(this.bymonthday, this.nth, gettext('and')));
  1024. }
  1025. // this.add(gettext('DAY'))
  1026. };
  1027. ToText.prototype._byweekday = function () {
  1028. var gettext = this.gettext;
  1029. if (this.byweekday.allWeeks && !this.byweekday.isWeekdays) {
  1030. this.add(gettext('on')).add(this.list(this.byweekday.allWeeks, this.weekdaytext));
  1031. }
  1032. if (this.byweekday.someWeeks) {
  1033. if (this.byweekday.allWeeks)
  1034. this.add(gettext('and'));
  1035. this.add(gettext('on the')).add(this.list(this.byweekday.someWeeks, this.weekdaytext, gettext('and')));
  1036. }
  1037. };
  1038. ToText.prototype._byhour = function () {
  1039. var gettext = this.gettext;
  1040. this.add(gettext('at')).add(this.list(this.origOptions.byhour, undefined, gettext('and')));
  1041. };
  1042. ToText.prototype._bymonth = function () {
  1043. this.add(this.list(this.options.bymonth, this.monthtext, this.gettext('and')));
  1044. };
  1045. ToText.prototype.nth = function (n) {
  1046. n = parseInt(n.toString(), 10);
  1047. var nth;
  1048. var npos;
  1049. var gettext = this.gettext;
  1050. if (n === -1)
  1051. return gettext('last');
  1052. npos = Math.abs(n);
  1053. switch (npos) {
  1054. case 1:
  1055. case 21:
  1056. case 31:
  1057. nth = npos + gettext('st');
  1058. break;
  1059. case 2:
  1060. case 22:
  1061. nth = npos + gettext('nd');
  1062. break;
  1063. case 3:
  1064. case 23:
  1065. nth = npos + gettext('rd');
  1066. break;
  1067. default:
  1068. nth = npos + gettext('th');
  1069. }
  1070. return n < 0 ? nth + ' ' + gettext('last') : nth;
  1071. };
  1072. ToText.prototype.monthtext = function (m) {
  1073. return this.language.monthNames[m - 1];
  1074. };
  1075. ToText.prototype.weekdaytext = function (wday) {
  1076. var weekday = isNumber(wday) ? (wday + 1) % 7 : wday.getJsWeekday();
  1077. return ((wday.n ? this.nth(wday.n) + ' ' : '') + this.language.dayNames[weekday]);
  1078. };
  1079. ToText.prototype.plural = function (n) {
  1080. return n % 100 !== 1;
  1081. };
  1082. ToText.prototype.add = function (s) {
  1083. this.text.push(' ');
  1084. this.text.push(s);
  1085. return this;
  1086. };
  1087. ToText.prototype.list = function (arr, callback, finalDelim, delim) {
  1088. if (delim === void 0) { delim = ','; }
  1089. if (!isArray(arr)) {
  1090. arr = [arr];
  1091. }
  1092. var delimJoin = function (array, delimiter, finalDelimiter) {
  1093. var list = '';
  1094. for (var i = 0; i < array.length; i++) {
  1095. if (i !== 0) {
  1096. if (i === array.length - 1) {
  1097. list += ' ' + finalDelimiter + ' ';
  1098. }
  1099. else {
  1100. list += delimiter + ' ';
  1101. }
  1102. }
  1103. list += array[i];
  1104. }
  1105. return list;
  1106. };
  1107. callback =
  1108. callback ||
  1109. function (o) {
  1110. return o.toString();
  1111. };
  1112. var self = this;
  1113. var realCallback = function (arg) {
  1114. return callback && callback.call(self, arg);
  1115. };
  1116. if (finalDelim) {
  1117. return delimJoin(arr.map(realCallback), delim, finalDelim);
  1118. }
  1119. else {
  1120. return arr.map(realCallback).join(delim + ' ');
  1121. }
  1122. };
  1123. return ToText;
  1124. }());
  1125. /* harmony default export */ var totext = (totext_ToText);
  1126. // CONCATENATED MODULE: ./src/nlp/parsetext.ts
  1127. // =============================================================================
  1128. // Parser
  1129. // =============================================================================
  1130. var Parser = /** @class */ (function () {
  1131. function Parser(rules) {
  1132. this.done = true;
  1133. this.rules = rules;
  1134. }
  1135. Parser.prototype.start = function (text) {
  1136. this.text = text;
  1137. this.done = false;
  1138. return this.nextSymbol();
  1139. };
  1140. Parser.prototype.isDone = function () {
  1141. return this.done && this.symbol === null;
  1142. };
  1143. Parser.prototype.nextSymbol = function () {
  1144. var best;
  1145. var bestSymbol;
  1146. var p = this;
  1147. this.symbol = null;
  1148. this.value = null;
  1149. do {
  1150. if (this.done)
  1151. return false;
  1152. var rule = void 0;
  1153. best = null;
  1154. for (var name_1 in this.rules) {
  1155. rule = this.rules[name_1];
  1156. var match = rule.exec(p.text);
  1157. if (match) {
  1158. if (best === null || match[0].length > best[0].length) {
  1159. best = match;
  1160. bestSymbol = name_1;
  1161. }
  1162. }
  1163. }
  1164. if (best != null) {
  1165. this.text = this.text.substr(best[0].length);
  1166. if (this.text === '')
  1167. this.done = true;
  1168. }
  1169. if (best == null) {
  1170. this.done = true;
  1171. this.symbol = null;
  1172. this.value = null;
  1173. return;
  1174. }
  1175. // @ts-ignore
  1176. } while (bestSymbol === 'SKIP');
  1177. // @ts-ignore
  1178. this.symbol = bestSymbol;
  1179. this.value = best;
  1180. return true;
  1181. };
  1182. Parser.prototype.accept = function (name) {
  1183. if (this.symbol === name) {
  1184. if (this.value) {
  1185. var v = this.value;
  1186. this.nextSymbol();
  1187. return v;
  1188. }
  1189. this.nextSymbol();
  1190. return true;
  1191. }
  1192. return false;
  1193. };
  1194. Parser.prototype.acceptNumber = function () {
  1195. return this.accept('number');
  1196. };
  1197. Parser.prototype.expect = function (name) {
  1198. if (this.accept(name))
  1199. return true;
  1200. throw new Error('expected ' + name + ' but found ' + this.symbol);
  1201. };
  1202. return Parser;
  1203. }());
  1204. function parseText(text, language) {
  1205. if (language === void 0) { language = i18n; }
  1206. var options = {};
  1207. var ttr = new Parser(language.tokens);
  1208. if (!ttr.start(text))
  1209. return null;
  1210. S();
  1211. return options;
  1212. function S() {
  1213. // every [n]
  1214. ttr.expect('every');
  1215. var n = ttr.acceptNumber();
  1216. if (n)
  1217. options.interval = parseInt(n[0], 10);
  1218. if (ttr.isDone())
  1219. throw new Error('Unexpected end');
  1220. switch (ttr.symbol) {
  1221. case 'day(s)':
  1222. options.freq = src.DAILY;
  1223. if (ttr.nextSymbol()) {
  1224. AT();
  1225. F();
  1226. }
  1227. break;
  1228. // FIXME Note: every 2 weekdays != every two weeks on weekdays.
  1229. // DAILY on weekdays is not a valid rule
  1230. case 'weekday(s)':
  1231. options.freq = src.WEEKLY;
  1232. options.byweekday = [
  1233. src.MO,
  1234. src.TU,
  1235. src.WE,
  1236. src.TH,
  1237. src.FR
  1238. ];
  1239. ttr.nextSymbol();
  1240. F();
  1241. break;
  1242. case 'week(s)':
  1243. options.freq = src.WEEKLY;
  1244. if (ttr.nextSymbol()) {
  1245. ON();
  1246. F();
  1247. }
  1248. break;
  1249. case 'hour(s)':
  1250. options.freq = src.HOURLY;
  1251. if (ttr.nextSymbol()) {
  1252. ON();
  1253. F();
  1254. }
  1255. break;
  1256. case 'minute(s)':
  1257. options.freq = src.MINUTELY;
  1258. if (ttr.nextSymbol()) {
  1259. ON();
  1260. F();
  1261. }
  1262. break;
  1263. case 'month(s)':
  1264. options.freq = src.MONTHLY;
  1265. if (ttr.nextSymbol()) {
  1266. ON();
  1267. F();
  1268. }
  1269. break;
  1270. case 'year(s)':
  1271. options.freq = src.YEARLY;
  1272. if (ttr.nextSymbol()) {
  1273. ON();
  1274. F();
  1275. }
  1276. break;
  1277. case 'monday':
  1278. case 'tuesday':
  1279. case 'wednesday':
  1280. case 'thursday':
  1281. case 'friday':
  1282. case 'saturday':
  1283. case 'sunday':
  1284. options.freq = src.WEEKLY;
  1285. var key = ttr.symbol.substr(0, 2).toUpperCase();
  1286. options.byweekday = [src[key]];
  1287. if (!ttr.nextSymbol())
  1288. return;
  1289. // TODO check for duplicates
  1290. while (ttr.accept('comma')) {
  1291. if (ttr.isDone())
  1292. throw new Error('Unexpected end');
  1293. var wkd = decodeWKD();
  1294. if (!wkd) {
  1295. throw new Error('Unexpected symbol ' + ttr.symbol + ', expected weekday');
  1296. }
  1297. // @ts-ignore
  1298. options.byweekday.push(src[wkd]);
  1299. ttr.nextSymbol();
  1300. }
  1301. MDAYs();
  1302. F();
  1303. break;
  1304. case 'january':
  1305. case 'february':
  1306. case 'march':
  1307. case 'april':
  1308. case 'may':
  1309. case 'june':
  1310. case 'july':
  1311. case 'august':
  1312. case 'september':
  1313. case 'october':
  1314. case 'november':
  1315. case 'december':
  1316. options.freq = src.YEARLY;
  1317. options.bymonth = [decodeM()];
  1318. if (!ttr.nextSymbol())
  1319. return;
  1320. // TODO check for duplicates
  1321. while (ttr.accept('comma')) {
  1322. if (ttr.isDone())
  1323. throw new Error('Unexpected end');
  1324. var m = decodeM();
  1325. if (!m) {
  1326. throw new Error('Unexpected symbol ' + ttr.symbol + ', expected month');
  1327. }
  1328. options.bymonth.push(m);
  1329. ttr.nextSymbol();
  1330. }
  1331. ON();
  1332. F();
  1333. break;
  1334. default:
  1335. throw new Error('Unknown symbol');
  1336. }
  1337. }
  1338. function ON() {
  1339. var on = ttr.accept('on');
  1340. var the = ttr.accept('the');
  1341. if (!(on || the))
  1342. return;
  1343. do {
  1344. var nth = decodeNTH();
  1345. var wkd = decodeWKD();
  1346. var m = decodeM();
  1347. // nth <weekday> | <weekday>
  1348. if (nth) {
  1349. // ttr.nextSymbol()
  1350. if (wkd) {
  1351. ttr.nextSymbol();
  1352. if (!options.byweekday)
  1353. options.byweekday = [];
  1354. // @ts-ignore
  1355. options.byweekday.push(src[wkd].nth(nth));
  1356. }
  1357. else {
  1358. if (!options.bymonthday)
  1359. options.bymonthday = [];
  1360. // @ts-ignore
  1361. options.bymonthday.push(nth);
  1362. ttr.accept('day(s)');
  1363. }
  1364. // <weekday>
  1365. }
  1366. else if (wkd) {
  1367. ttr.nextSymbol();
  1368. if (!options.byweekday)
  1369. options.byweekday = [];
  1370. // @ts-ignore
  1371. options.byweekday.push(src[wkd]);
  1372. }
  1373. else if (ttr.symbol === 'weekday(s)') {
  1374. ttr.nextSymbol();
  1375. if (!options.byweekday) {
  1376. options.byweekday = [
  1377. src.MO,
  1378. src.TU,
  1379. src.WE,
  1380. src.TH,
  1381. src.FR
  1382. ];
  1383. }
  1384. }
  1385. else if (ttr.symbol === 'week(s)') {
  1386. ttr.nextSymbol();
  1387. var n = ttr.acceptNumber();
  1388. if (!n) {
  1389. throw new Error('Unexpected symbol ' + ttr.symbol + ', expected week number');
  1390. }
  1391. options.byweekno = [parseInt(n[0], 10)];
  1392. while (ttr.accept('comma')) {
  1393. n = ttr.acceptNumber();
  1394. if (!n) {
  1395. throw new Error('Unexpected symbol ' + ttr.symbol + '; expected monthday');
  1396. }
  1397. options.byweekno.push(parseInt(n[0], 10));
  1398. }
  1399. }
  1400. else if (m) {
  1401. ttr.nextSymbol();
  1402. if (!options.bymonth)
  1403. options.bymonth = [];
  1404. // @ts-ignore
  1405. options.bymonth.push(m);
  1406. }
  1407. else {
  1408. return;
  1409. }
  1410. } while (ttr.accept('comma') || ttr.accept('the') || ttr.accept('on'));
  1411. }
  1412. function AT() {
  1413. var at = ttr.accept('at');
  1414. if (!at)
  1415. return;
  1416. do {
  1417. var n = ttr.acceptNumber();
  1418. if (!n) {
  1419. throw new Error('Unexpected symbol ' + ttr.symbol + ', expected hour');
  1420. }
  1421. options.byhour = [parseInt(n[0], 10)];
  1422. while (ttr.accept('comma')) {
  1423. n = ttr.acceptNumber();
  1424. if (!n) {
  1425. throw new Error('Unexpected symbol ' + ttr.symbol + '; expected hour');
  1426. }
  1427. options.byhour.push(parseInt(n[0], 10));
  1428. }
  1429. } while (ttr.accept('comma') || ttr.accept('at'));
  1430. }
  1431. function decodeM() {
  1432. switch (ttr.symbol) {
  1433. case 'january':
  1434. return 1;
  1435. case 'february':
  1436. return 2;
  1437. case 'march':
  1438. return 3;
  1439. case 'april':
  1440. return 4;
  1441. case 'may':
  1442. return 5;
  1443. case 'june':
  1444. return 6;
  1445. case 'july':
  1446. return 7;
  1447. case 'august':
  1448. return 8;
  1449. case 'september':
  1450. return 9;
  1451. case 'october':
  1452. return 10;
  1453. case 'november':
  1454. return 11;
  1455. case 'december':
  1456. return 12;
  1457. default:
  1458. return false;
  1459. }
  1460. }
  1461. function decodeWKD() {
  1462. switch (ttr.symbol) {
  1463. case 'monday':
  1464. case 'tuesday':
  1465. case 'wednesday':
  1466. case 'thursday':
  1467. case 'friday':
  1468. case 'saturday':
  1469. case 'sunday':
  1470. return ttr.symbol.substr(0, 2).toUpperCase();
  1471. default:
  1472. return false;
  1473. }
  1474. }
  1475. function decodeNTH() {
  1476. switch (ttr.symbol) {
  1477. case 'last':
  1478. ttr.nextSymbol();
  1479. return -1;
  1480. case 'first':
  1481. ttr.nextSymbol();
  1482. return 1;
  1483. case 'second':
  1484. ttr.nextSymbol();
  1485. return ttr.accept('last') ? -2 : 2;
  1486. case 'third':
  1487. ttr.nextSymbol();
  1488. return ttr.accept('last') ? -3 : 3;
  1489. case 'nth':
  1490. var v = parseInt(ttr.value[1], 10);
  1491. if (v < -366 || v > 366)
  1492. throw new Error('Nth out of range: ' + v);
  1493. ttr.nextSymbol();
  1494. return ttr.accept('last') ? -v : v;
  1495. default:
  1496. return false;
  1497. }
  1498. }
  1499. function MDAYs() {
  1500. ttr.accept('on');
  1501. ttr.accept('the');
  1502. var nth = decodeNTH();
  1503. if (!nth)
  1504. return;
  1505. options.bymonthday = [nth];
  1506. ttr.nextSymbol();
  1507. while (ttr.accept('comma')) {
  1508. nth = decodeNTH();
  1509. if (!nth) {
  1510. throw new Error('Unexpected symbol ' + ttr.symbol + '; expected monthday');
  1511. }
  1512. options.bymonthday.push(nth);
  1513. ttr.nextSymbol();
  1514. }
  1515. }
  1516. function F() {
  1517. if (ttr.symbol === 'until') {
  1518. var date = Date.parse(ttr.text);
  1519. if (!date)
  1520. throw new Error('Cannot parse until date:' + ttr.text);
  1521. options.until = new Date(date);
  1522. }
  1523. else if (ttr.accept('for')) {
  1524. options.count = parseInt(ttr.value[0], 10);
  1525. ttr.expect('number');
  1526. // ttr.expect('times')
  1527. }
  1528. }
  1529. }
  1530. // CONCATENATED MODULE: ./src/types.ts
  1531. var Frequency;
  1532. (function (Frequency) {
  1533. Frequency[Frequency["YEARLY"] = 0] = "YEARLY";
  1534. Frequency[Frequency["MONTHLY"] = 1] = "MONTHLY";
  1535. Frequency[Frequency["WEEKLY"] = 2] = "WEEKLY";
  1536. Frequency[Frequency["DAILY"] = 3] = "DAILY";
  1537. Frequency[Frequency["HOURLY"] = 4] = "HOURLY";
  1538. Frequency[Frequency["MINUTELY"] = 5] = "MINUTELY";
  1539. Frequency[Frequency["SECONDLY"] = 6] = "SECONDLY";
  1540. })(Frequency || (Frequency = {}));
  1541. function freqIsDailyOrGreater(freq) {
  1542. return freq < Frequency.HOURLY;
  1543. }
  1544. // CONCATENATED MODULE: ./src/nlp/index.ts
  1545. /*!
  1546. * rrule.js - Library for working with recurrence rules for calendar dates.
  1547. * https://github.com/jakubroztocil/rrule
  1548. *
  1549. * Copyright 2010, Jakub Roztocil and Lars Schoning
  1550. * Licenced under the BSD licence.
  1551. * https://github.com/jakubroztocil/rrule/blob/master/LICENCE
  1552. *
  1553. */
  1554. /**
  1555. *
  1556. * Implementation of RRule.fromText() and RRule::toText().
  1557. *
  1558. *
  1559. * On the client side, this file needs to be included
  1560. * when those functions are used.
  1561. *
  1562. */
  1563. // =============================================================================
  1564. // fromText
  1565. // =============================================================================
  1566. /**
  1567. * Will be able to convert some of the below described rules from
  1568. * text format to a rule object.
  1569. *
  1570. *
  1571. * RULES
  1572. *
  1573. * Every ([n])
  1574. * day(s)
  1575. * | [weekday], ..., (and) [weekday]
  1576. * | weekday(s)
  1577. * | week(s)
  1578. * | month(s)
  1579. * | [month], ..., (and) [month]
  1580. * | year(s)
  1581. *
  1582. *
  1583. * Plus 0, 1, or multiple of these:
  1584. *
  1585. * on [weekday], ..., (or) [weekday] the [monthday], [monthday], ... (or) [monthday]
  1586. *
  1587. * on [weekday], ..., (and) [weekday]
  1588. *
  1589. * on the [monthday], [monthday], ... (and) [monthday] (day of the month)
  1590. *
  1591. * on the [nth-weekday], ..., (and) [nth-weekday] (of the month/year)
  1592. *
  1593. *
  1594. * Plus 0 or 1 of these:
  1595. *
  1596. * for [n] time(s)
  1597. *
  1598. * until [date]
  1599. *
  1600. * Plus (.)
  1601. *
  1602. *
  1603. * Definitely no supported for parsing:
  1604. *
  1605. * (for year):
  1606. * in week(s) [n], ..., (and) [n]
  1607. *
  1608. * on the [yearday], ..., (and) [n] day of the year
  1609. * on day [yearday], ..., (and) [n]
  1610. *
  1611. *
  1612. * NON-TERMINALS
  1613. *
  1614. * [n]: 1, 2 ..., one, two, three ..
  1615. * [month]: January, February, March, April, May, ... December
  1616. * [weekday]: Monday, ... Sunday
  1617. * [nth-weekday]: first [weekday], 2nd [weekday], ... last [weekday], ...
  1618. * [monthday]: first, 1., 2., 1st, 2nd, second, ... 31st, last day, 2nd last day, ..
  1619. * [date]:
  1620. * [month] (0-31(,) ([year])),
  1621. * (the) 0-31.(1-12.([year])),
  1622. * (the) 0-31/(1-12/([year])),
  1623. * [weekday]
  1624. *
  1625. * [year]: 0000, 0001, ... 01, 02, ..
  1626. *
  1627. * Definitely not supported for parsing:
  1628. *
  1629. * [yearday]: first, 1., 2., 1st, 2nd, second, ... 366th, last day, 2nd last day, ..
  1630. *
  1631. * @param {String} text
  1632. * @return {Object, Boolean} the rule, or null.
  1633. */
  1634. var fromText = function (text, language) {
  1635. if (language === void 0) { language = i18n; }
  1636. return new src(parseText(text, language) || undefined);
  1637. };
  1638. var common = [
  1639. 'count',
  1640. 'until',
  1641. 'interval',
  1642. 'byweekday',
  1643. 'bymonthday',
  1644. 'bymonth'
  1645. ];
  1646. totext.IMPLEMENTED = [];
  1647. totext.IMPLEMENTED[Frequency.HOURLY] = common;
  1648. totext.IMPLEMENTED[Frequency.MINUTELY] = common;
  1649. totext.IMPLEMENTED[Frequency.DAILY] = ['byhour'].concat(common);
  1650. totext.IMPLEMENTED[Frequency.WEEKLY] = common;
  1651. totext.IMPLEMENTED[Frequency.MONTHLY] = common;
  1652. totext.IMPLEMENTED[Frequency.YEARLY] = ['byweekno', 'byyearday'].concat(common);
  1653. // =============================================================================
  1654. // Export
  1655. // =============================================================================
  1656. var toText = function (rrule, gettext, language, dateFormatter) {
  1657. return new totext(rrule, gettext, language, dateFormatter).toString();
  1658. };
  1659. var isFullyConvertible = totext.isFullyConvertible;
  1660. // CONCATENATED MODULE: ./src/datetime.ts
  1661. var Time = /** @class */ (function () {
  1662. function Time(hour, minute, second, millisecond) {
  1663. this.hour = hour;
  1664. this.minute = minute;
  1665. this.second = second;
  1666. this.millisecond = millisecond || 0;
  1667. }
  1668. Time.prototype.getHours = function () {
  1669. return this.hour;
  1670. };
  1671. Time.prototype.getMinutes = function () {
  1672. return this.minute;
  1673. };
  1674. Time.prototype.getSeconds = function () {
  1675. return this.second;
  1676. };
  1677. Time.prototype.getMilliseconds = function () {
  1678. return this.millisecond;
  1679. };
  1680. Time.prototype.getTime = function () {
  1681. return ((this.hour * 60 * 60 + this.minute * 60 + this.second) * 1000 +
  1682. this.millisecond);
  1683. };
  1684. return Time;
  1685. }());
  1686. var datetime_DateTime = /** @class */ (function (_super) {
  1687. __extends(DateTime, _super);
  1688. function DateTime(year, month, day, hour, minute, second, millisecond) {
  1689. var _this = _super.call(this, hour, minute, second, millisecond) || this;
  1690. _this.year = year;
  1691. _this.month = month;
  1692. _this.day = day;
  1693. return _this;
  1694. }
  1695. DateTime.fromDate = function (date) {
  1696. return new this(date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.valueOf() % 1000);
  1697. };
  1698. DateTime.prototype.getWeekday = function () {
  1699. return dateutil_dateutil.getWeekday(new Date(this.getTime()));
  1700. };
  1701. DateTime.prototype.getTime = function () {
  1702. return new Date(Date.UTC(this.year, this.month - 1, this.day, this.hour, this.minute, this.second, this.millisecond)).getTime();
  1703. };
  1704. DateTime.prototype.getDay = function () {
  1705. return this.day;
  1706. };
  1707. DateTime.prototype.getMonth = function () {
  1708. return this.month;
  1709. };
  1710. DateTime.prototype.getYear = function () {
  1711. return this.year;
  1712. };
  1713. DateTime.prototype.addYears = function (years) {
  1714. this.year += years;
  1715. };
  1716. DateTime.prototype.addMonths = function (months) {
  1717. this.month += months;
  1718. if (this.month > 12) {
  1719. var yearDiv = Math.floor(this.month / 12);
  1720. var monthMod = pymod(this.month, 12);
  1721. this.month = monthMod;
  1722. this.year += yearDiv;
  1723. if (this.month === 0) {
  1724. this.month = 12;
  1725. --this.year;
  1726. }
  1727. }
  1728. };
  1729. DateTime.prototype.addWeekly = function (days, wkst) {
  1730. if (wkst > this.getWeekday()) {
  1731. this.day += -(this.getWeekday() + 1 + (6 - wkst)) + days * 7;
  1732. }
  1733. else {
  1734. this.day += -(this.getWeekday() - wkst) + days * 7;
  1735. }
  1736. this.fixDay();
  1737. };
  1738. DateTime.prototype.addDaily = function (days) {
  1739. this.day += days;
  1740. this.fixDay();
  1741. };
  1742. DateTime.prototype.addHours = function (hours, filtered, byhour) {
  1743. if (filtered) {
  1744. // Jump to one iteration before next day
  1745. this.hour += Math.floor((23 - this.hour) / hours) * hours;
  1746. }
  1747. while (true) {
  1748. this.hour += hours;
  1749. var _a = divmod(this.hour, 24), dayDiv = _a.div, hourMod = _a.mod;
  1750. if (dayDiv) {
  1751. this.hour = hourMod;
  1752. this.addDaily(dayDiv);
  1753. }
  1754. if (empty(byhour) || includes(byhour, this.hour))
  1755. break;
  1756. }
  1757. };
  1758. DateTime.prototype.addMinutes = function (minutes, filtered, byhour, byminute) {
  1759. if (filtered) {
  1760. // Jump to one iteration before next day
  1761. this.minute +=
  1762. Math.floor((1439 - (this.hour * 60 + this.minute)) / minutes) * minutes;
  1763. }
  1764. while (true) {
  1765. this.minute += minutes;
  1766. var _a = divmod(this.minute, 60), hourDiv = _a.div, minuteMod = _a.mod;
  1767. if (hourDiv) {
  1768. this.minute = minuteMod;
  1769. this.addHours(hourDiv, false, byhour);
  1770. }
  1771. if ((empty(byhour) || includes(byhour, this.hour)) &&
  1772. (empty(byminute) || includes(byminute, this.minute))) {
  1773. break;
  1774. }
  1775. }
  1776. };
  1777. DateTime.prototype.addSeconds = function (seconds, filtered, byhour, byminute, bysecond) {
  1778. if (filtered) {
  1779. // Jump to one iteration before next day
  1780. this.second +=
  1781. Math.floor((86399 - (this.hour * 3600 + this.minute * 60 + this.second)) / seconds) * seconds;
  1782. }
  1783. while (true) {
  1784. this.second += seconds;
  1785. var _a = divmod(this.second, 60), minuteDiv = _a.div, secondMod = _a.mod;
  1786. if (minuteDiv) {
  1787. this.second = secondMod;
  1788. this.addMinutes(minuteDiv, false, byhour, byminute);
  1789. }
  1790. if ((empty(byhour) || includes(byhour, this.hour)) &&
  1791. (empty(byminute) || includes(byminute, this.minute)) &&
  1792. (empty(bysecond) || includes(bysecond, this.second))) {
  1793. break;
  1794. }
  1795. }
  1796. };
  1797. DateTime.prototype.fixDay = function () {
  1798. if (this.day <= 28) {
  1799. return;
  1800. }
  1801. var daysinmonth = dateutil_dateutil.monthRange(this.year, this.month - 1)[1];
  1802. if (this.day <= daysinmonth) {
  1803. return;
  1804. }
  1805. while (this.day > daysinmonth) {
  1806. this.day -= daysinmonth;
  1807. ++this.month;
  1808. if (this.month === 13) {
  1809. this.month = 1;
  1810. ++this.year;
  1811. if (this.year > dateutil_dateutil.MAXYEAR) {
  1812. return;
  1813. }
  1814. }
  1815. daysinmonth = dateutil_dateutil.monthRange(this.year, this.month - 1)[1];
  1816. }
  1817. };
  1818. DateTime.prototype.add = function (options, filtered) {
  1819. var freq = options.freq, interval = options.interval, wkst = options.wkst, byhour = options.byhour, byminute = options.byminute, bysecond = options.bysecond;
  1820. switch (freq) {
  1821. case Frequency.YEARLY: return this.addYears(interval);
  1822. case Frequency.MONTHLY: return this.addMonths(interval);
  1823. case Frequency.WEEKLY: return this.addWeekly(interval, wkst);
  1824. case Frequency.DAILY: return this.addDaily(interval);
  1825. case Frequency.HOURLY: return this.addHours(interval, filtered, byhour);
  1826. case Frequency.MINUTELY: return this.addMinutes(interval, filtered, byhour, byminute);
  1827. case Frequency.SECONDLY: return this.addSeconds(interval, filtered, byhour, byminute, bysecond);
  1828. }
  1829. };
  1830. return DateTime;
  1831. }(Time));
  1832. // CONCATENATED MODULE: ./src/parseoptions.ts
  1833. function initializeOptions(options) {
  1834. var invalid = [];
  1835. var keys = Object.keys(options);
  1836. // Shallow copy for options and origOptions and check for invalid
  1837. for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
  1838. var key = keys_1[_i];
  1839. if (!includes(rrule_defaultKeys, key))
  1840. invalid.push(key);
  1841. if (src_dateutil.isDate(options[key]) && !src_dateutil.isValidDate(options[key]))
  1842. invalid.push(key);
  1843. }
  1844. if (invalid.length) {
  1845. throw new Error('Invalid options: ' + invalid.join(', '));
  1846. }
  1847. return __assign({}, options);
  1848. }
  1849. function parseOptions(options) {
  1850. var opts = __assign(__assign({}, DEFAULT_OPTIONS), initializeOptions(options));
  1851. if (isPresent(opts.byeaster))
  1852. opts.freq = src_rrule.YEARLY;
  1853. if (!(isPresent(opts.freq) && src_rrule.FREQUENCIES[opts.freq])) {
  1854. throw new Error("Invalid frequency: " + opts.freq + " " + options.freq);
  1855. }
  1856. if (!opts.dtstart)
  1857. opts.dtstart = new Date(new Date().setMilliseconds(0));
  1858. if (!isPresent(opts.wkst)) {
  1859. opts.wkst = src_rrule.MO.weekday;
  1860. }
  1861. else if (isNumber(opts.wkst)) {
  1862. // cool, just keep it like that
  1863. }
  1864. else {
  1865. opts.wkst = opts.wkst.weekday;
  1866. }
  1867. if (isPresent(opts.bysetpos)) {
  1868. if (isNumber(opts.bysetpos))
  1869. opts.bysetpos = [opts.bysetpos];
  1870. for (var i = 0; i < opts.bysetpos.length; i++) {
  1871. var v = opts.bysetpos[i];
  1872. if (v === 0 || !(v >= -366 && v <= 366)) {
  1873. throw new Error('bysetpos must be between 1 and 366,' + ' or between -366 and -1');
  1874. }
  1875. }
  1876. }
  1877. if (!(Boolean(opts.byweekno) ||
  1878. notEmpty(opts.byweekno) ||
  1879. notEmpty(opts.byyearday) ||
  1880. Boolean(opts.bymonthday) ||
  1881. notEmpty(opts.bymonthday) ||
  1882. isPresent(opts.byweekday) ||
  1883. isPresent(opts.byeaster))) {
  1884. switch (opts.freq) {
  1885. case src_rrule.YEARLY:
  1886. if (!opts.bymonth)
  1887. opts.bymonth = opts.dtstart.getUTCMonth() + 1;
  1888. opts.bymonthday = opts.dtstart.getUTCDate();
  1889. break;
  1890. case src_rrule.MONTHLY:
  1891. opts.bymonthday = opts.dtstart.getUTCDate();
  1892. break;
  1893. case src_rrule.WEEKLY:
  1894. opts.byweekday = [src_dateutil.getWeekday(opts.dtstart)];
  1895. break;
  1896. }
  1897. }
  1898. // bymonth
  1899. if (isPresent(opts.bymonth) && !isArray(opts.bymonth)) {
  1900. opts.bymonth = [opts.bymonth];
  1901. }
  1902. // byyearday
  1903. if (isPresent(opts.byyearday) &&
  1904. !isArray(opts.byyearday) &&
  1905. isNumber(opts.byyearday)) {
  1906. opts.byyearday = [opts.byyearday];
  1907. }
  1908. // bymonthday
  1909. if (!isPresent(opts.bymonthday)) {
  1910. opts.bymonthday = [];
  1911. opts.bynmonthday = [];
  1912. }
  1913. else if (isArray(opts.bymonthday)) {
  1914. var bymonthday = [];
  1915. var bynmonthday = [];
  1916. for (var i = 0; i < opts.bymonthday.length; i++) {
  1917. var v = opts.bymonthday[i];
  1918. if (v > 0) {
  1919. bymonthday.push(v);
  1920. }
  1921. else if (v < 0) {
  1922. bynmonthday.push(v);
  1923. }
  1924. }
  1925. opts.bymonthday = bymonthday;
  1926. opts.bynmonthday = bynmonthday;
  1927. }
  1928. else if (opts.bymonthday < 0) {
  1929. opts.bynmonthday = [opts.bymonthday];
  1930. opts.bymonthday = [];
  1931. }
  1932. else {
  1933. opts.bynmonthday = [];
  1934. opts.bymonthday = [opts.bymonthday];
  1935. }
  1936. // byweekno
  1937. if (isPresent(opts.byweekno) && !isArray(opts.byweekno)) {
  1938. opts.byweekno = [opts.byweekno];
  1939. }
  1940. // byweekday / bynweekday
  1941. if (!isPresent(opts.byweekday)) {
  1942. opts.bynweekday = null;
  1943. }
  1944. else if (isNumber(opts.byweekday)) {
  1945. opts.byweekday = [opts.byweekday];
  1946. opts.bynweekday = null;
  1947. }
  1948. else if (isWeekdayStr(opts.byweekday)) {
  1949. opts.byweekday = [Weekday.fromStr(opts.byweekday).weekday];
  1950. opts.bynweekday = null;
  1951. }
  1952. else if (opts.byweekday instanceof Weekday) {
  1953. if (!opts.byweekday.n || opts.freq > src_rrule.MONTHLY) {
  1954. opts.byweekday = [opts.byweekday.weekday];
  1955. opts.bynweekday = null;
  1956. }
  1957. else {
  1958. opts.bynweekday = [[opts.byweekday.weekday, opts.byweekday.n]];
  1959. opts.byweekday = null;
  1960. }
  1961. }
  1962. else {
  1963. var byweekday = [];
  1964. var bynweekday = [];
  1965. for (var i = 0; i < opts.byweekday.length; i++) {
  1966. var wday = opts.byweekday[i];
  1967. if (isNumber(wday)) {
  1968. byweekday.push(wday);
  1969. continue;
  1970. }
  1971. else if (isWeekdayStr(wday)) {
  1972. byweekday.push(Weekday.fromStr(wday).weekday);
  1973. continue;
  1974. }
  1975. if (!wday.n || opts.freq > src_rrule.MONTHLY) {
  1976. byweekday.push(wday.weekday);
  1977. }
  1978. else {
  1979. bynweekday.push([wday.weekday, wday.n]);
  1980. }
  1981. }
  1982. opts.byweekday = notEmpty(byweekday) ? byweekday : null;
  1983. opts.bynweekday = notEmpty(bynweekday) ? bynweekday : null;
  1984. }
  1985. // byhour
  1986. if (!isPresent(opts.byhour)) {
  1987. opts.byhour =
  1988. opts.freq < src_rrule.HOURLY ? [opts.dtstart.getUTCHours()] : null;
  1989. }
  1990. else if (isNumber(opts.byhour)) {
  1991. opts.byhour = [opts.byhour];
  1992. }
  1993. // byminute
  1994. if (!isPresent(opts.byminute)) {
  1995. opts.byminute =
  1996. opts.freq < src_rrule.MINUTELY ? [opts.dtstart.getUTCMinutes()] : null;
  1997. }
  1998. else if (isNumber(opts.byminute)) {
  1999. opts.byminute = [opts.byminute];
  2000. }
  2001. // bysecond
  2002. if (!isPresent(opts.bysecond)) {
  2003. opts.bysecond =
  2004. opts.freq < src_rrule.SECONDLY ? [opts.dtstart.getUTCSeconds()] : null;
  2005. }
  2006. else if (isNumber(opts.bysecond)) {
  2007. opts.bysecond = [opts.bysecond];
  2008. }
  2009. return { parsedOptions: opts };
  2010. }
  2011. function buildTimeset(opts) {
  2012. var millisecondModulo = opts.dtstart.getTime() % 1000;
  2013. if (!freqIsDailyOrGreater(opts.freq)) {
  2014. return [];
  2015. }
  2016. var timeset = [];
  2017. opts.byhour.forEach(function (hour) {
  2018. opts.byminute.forEach(function (minute) {
  2019. opts.bysecond.forEach(function (second) {
  2020. timeset.push(new Time(hour, minute, second, millisecondModulo));
  2021. });
  2022. });
  2023. });
  2024. return timeset;
  2025. }
  2026. // CONCATENATED MODULE: ./src/parsestring.ts
  2027. function parseString(rfcString) {
  2028. var options = rfcString.split('\n').map(parseLine).filter(function (x) { return x !== null; });
  2029. return __assign(__assign({}, options[0]), options[1]);
  2030. }
  2031. function parseDtstart(line) {
  2032. var options = {};
  2033. var dtstartWithZone = /DTSTART(?:;TZID=([^:=]+?))?(?::|=)([^;\s]+)/i.exec(line);
  2034. if (!dtstartWithZone) {
  2035. return options;
  2036. }
  2037. var _ = dtstartWithZone[0], tzid = dtstartWithZone[1], dtstart = dtstartWithZone[2];
  2038. if (tzid) {
  2039. options.tzid = tzid;
  2040. }
  2041. options.dtstart = src_dateutil.untilStringToDate(dtstart);
  2042. return options;
  2043. }
  2044. function parseLine(rfcString) {
  2045. rfcString = rfcString.replace(/^\s+|\s+$/, '');
  2046. if (!rfcString.length)
  2047. return null;
  2048. var header = /^([A-Z]+?)[:;]/.exec(rfcString.toUpperCase());
  2049. if (!header) {
  2050. return parseRrule(rfcString);
  2051. }
  2052. var _ = header[0], key = header[1];
  2053. switch (key.toUpperCase()) {
  2054. case 'RRULE':
  2055. case 'EXRULE':
  2056. return parseRrule(rfcString);
  2057. case 'DTSTART':
  2058. return parseDtstart(rfcString);
  2059. default:
  2060. throw new Error("Unsupported RFC prop " + key + " in " + rfcString);
  2061. }
  2062. }
  2063. function parseRrule(line) {
  2064. var strippedLine = line.replace(/^RRULE:/i, '');
  2065. var options = parseDtstart(strippedLine);
  2066. var attrs = line.replace(/^(?:RRULE|EXRULE):/i, '').split(';');
  2067. attrs.forEach(function (attr) {
  2068. var _a = attr.split('='), key = _a[0], value = _a[1];
  2069. switch (key.toUpperCase()) {
  2070. case 'FREQ':
  2071. options.freq = Frequency[value.toUpperCase()];
  2072. break;
  2073. case 'WKST':
  2074. options.wkst = Days[value.toUpperCase()];
  2075. break;
  2076. case 'COUNT':
  2077. case 'INTERVAL':
  2078. case 'BYSETPOS':
  2079. case 'BYMONTH':
  2080. case 'BYMONTHDAY':
  2081. case 'BYYEARDAY':
  2082. case 'BYWEEKNO':
  2083. case 'BYHOUR':
  2084. case 'BYMINUTE':
  2085. case 'BYSECOND':
  2086. var num = parseNumber(value);
  2087. var optionKey = key.toLowerCase();
  2088. // @ts-ignore
  2089. options[optionKey] = num;
  2090. break;
  2091. case 'BYWEEKDAY':
  2092. case 'BYDAY':
  2093. options.byweekday = parseWeekday(value);
  2094. break;
  2095. case 'DTSTART':
  2096. case 'TZID':
  2097. // for backwards compatibility
  2098. var dtstart = parseDtstart(line);
  2099. options.tzid = dtstart.tzid;
  2100. options.dtstart = dtstart.dtstart;
  2101. break;
  2102. case 'UNTIL':
  2103. options.until = src_dateutil.untilStringToDate(value);
  2104. break;
  2105. case 'BYEASTER':
  2106. options.byeaster = Number(value);
  2107. break;
  2108. default:
  2109. throw new Error("Unknown RRULE property '" + key + "'");
  2110. }
  2111. });
  2112. return options;
  2113. }
  2114. function parseNumber(value) {
  2115. if (value.indexOf(',') !== -1) {
  2116. var values = value.split(',');
  2117. return values.map(parseIndividualNumber);
  2118. }
  2119. return parseIndividualNumber(value);
  2120. }
  2121. function parseIndividualNumber(value) {
  2122. if (/^[+-]?\d+$/.test(value)) {
  2123. return Number(value);
  2124. }
  2125. return value;
  2126. }
  2127. function parseWeekday(value) {
  2128. var days = value.split(',');
  2129. return days.map(function (day) {
  2130. if (day.length === 2) {
  2131. // MO, TU, ...
  2132. return Days[day]; // wday instanceof Weekday
  2133. }
  2134. // -1MO, +3FR, 1SO, 13TU ...
  2135. var parts = day.match(/^([+-]?\d{1,2})([A-Z]{2})$/);
  2136. var n = Number(parts[1]);
  2137. var wdaypart = parts[2];
  2138. var wday = Days[wdaypart].weekday;
  2139. return new Weekday(wday, n);
  2140. });
  2141. }
  2142. // CONCATENATED MODULE: ./src/fake-luxon.ts
  2143. var fake_luxon_DateTime = {
  2144. fromJSDate: function () {
  2145. throw new TypeError();
  2146. }
  2147. };
  2148. // CONCATENATED MODULE: ./src/datewithzone.ts
  2149. var datewithzone_DateWithZone = /** @class */ (function () {
  2150. function DateWithZone(date, tzid) {
  2151. this.date = date;
  2152. this.tzid = tzid;
  2153. }
  2154. Object.defineProperty(DateWithZone.prototype, "isUTC", {
  2155. get: function () {
  2156. return !this.tzid || this.tzid.toUpperCase() === 'UTC';
  2157. },
  2158. enumerable: true,
  2159. configurable: true
  2160. });
  2161. DateWithZone.prototype.toString = function () {
  2162. var datestr = src_dateutil.timeToUntilString(this.date.getTime(), this.isUTC);
  2163. if (!this.isUTC) {
  2164. return ";TZID=" + this.tzid + ":" + datestr;
  2165. }
  2166. return ":" + datestr;
  2167. };
  2168. DateWithZone.prototype.getTime = function () {
  2169. return this.date.getTime();
  2170. };
  2171. DateWithZone.prototype.rezonedDate = function () {
  2172. if (this.isUTC) {
  2173. return this.date;
  2174. }
  2175. try {
  2176. var datetime = fake_luxon_DateTime
  2177. .fromJSDate(this.date);
  2178. var rezoned = datetime.setZone(this.tzid, { keepLocalTime: true });
  2179. return rezoned.toJSDate();
  2180. }
  2181. catch (e) {
  2182. if (e instanceof TypeError) {
  2183. console.error('Using TZID without Luxon available is unsupported. Returned times are in UTC, not the requested time zone');
  2184. }
  2185. return this.date;
  2186. }
  2187. };
  2188. return DateWithZone;
  2189. }());
  2190. // CONCATENATED MODULE: ./src/optionstostring.ts
  2191. function optionsToString(options) {
  2192. var rrule = [];
  2193. var dtstart = '';
  2194. var keys = Object.keys(options);
  2195. var defaultKeys = Object.keys(DEFAULT_OPTIONS);
  2196. for (var i = 0; i < keys.length; i++) {
  2197. if (keys[i] === 'tzid')
  2198. continue;
  2199. if (!includes(defaultKeys, keys[i]))
  2200. continue;
  2201. var key = keys[i].toUpperCase();
  2202. var value = options[keys[i]];
  2203. var outValue = '';
  2204. if (!isPresent(value) || (isArray(value) && !value.length))
  2205. continue;
  2206. switch (key) {
  2207. case 'FREQ':
  2208. outValue = src_rrule.FREQUENCIES[options.freq];
  2209. break;
  2210. case 'WKST':
  2211. if (isNumber(value)) {
  2212. outValue = new Weekday(value).toString();
  2213. }
  2214. else {
  2215. outValue = value.toString();
  2216. }
  2217. break;
  2218. case 'BYWEEKDAY':
  2219. /*
  2220. NOTE: BYWEEKDAY is a special case.
  2221. RRule() deconstructs the rule.options.byweekday array
  2222. into an array of Weekday arguments.
  2223. On the other hand, rule.origOptions is an array of Weekdays.
  2224. We need to handle both cases here.
  2225. It might be worth change RRule to keep the Weekdays.
  2226. Also, BYWEEKDAY (used by RRule) vs. BYDAY (RFC)
  2227. */
  2228. key = 'BYDAY';
  2229. outValue = toArray(value).map(function (wday) {
  2230. if (wday instanceof Weekday) {
  2231. return wday;
  2232. }
  2233. if (isArray(wday)) {
  2234. return new Weekday(wday[0], wday[1]);
  2235. }
  2236. return new Weekday(wday);
  2237. }).toString();
  2238. break;
  2239. case 'DTSTART':
  2240. dtstart = buildDtstart(value, options.tzid);
  2241. break;
  2242. case 'UNTIL':
  2243. outValue = src_dateutil.timeToUntilString(value, !options.tzid);
  2244. break;
  2245. default:
  2246. if (isArray(value)) {
  2247. var strValues = [];
  2248. for (var j = 0; j < value.length; j++) {
  2249. strValues[j] = String(value[j]);
  2250. }
  2251. outValue = strValues.toString();
  2252. }
  2253. else {
  2254. outValue = String(value);
  2255. }
  2256. }
  2257. if (outValue) {
  2258. rrule.push([key, outValue]);
  2259. }
  2260. }
  2261. var rules = rrule.map(function (_a) {
  2262. var key = _a[0], value = _a[1];
  2263. return key + "=" + value.toString();
  2264. }).join(';');
  2265. var ruleString = '';
  2266. if (rules !== '') {
  2267. ruleString = "RRULE:" + rules;
  2268. }
  2269. return [dtstart, ruleString].filter(function (x) { return !!x; }).join('\n');
  2270. }
  2271. function buildDtstart(dtstart, tzid) {
  2272. if (!dtstart) {
  2273. return '';
  2274. }
  2275. return 'DTSTART' + new datewithzone_DateWithZone(new Date(dtstart), tzid).toString();
  2276. }
  2277. // CONCATENATED MODULE: ./src/cache.ts
  2278. var cache_Cache = /** @class */ (function () {
  2279. function Cache() {
  2280. this.all = false;
  2281. this.before = [];
  2282. this.after = [];
  2283. this.between = [];
  2284. }
  2285. /**
  2286. * @param {String} what - all/before/after/between
  2287. * @param {Array,Date} value - an array of dates, one date, or null
  2288. * @param {Object?} args - _iter arguments
  2289. */
  2290. Cache.prototype._cacheAdd = function (what, value, args) {
  2291. if (value) {
  2292. value =
  2293. value instanceof Date
  2294. ? src_dateutil.clone(value)
  2295. : src_dateutil.cloneDates(value);
  2296. }
  2297. if (what === 'all') {
  2298. this.all = value;
  2299. }
  2300. else {
  2301. args._value = value;
  2302. this[what].push(args);
  2303. }
  2304. };
  2305. /**
  2306. * @return false - not in the cache
  2307. * null - cached, but zero occurrences (before/after)
  2308. * Date - cached (before/after)
  2309. * [] - cached, but zero occurrences (all/between)
  2310. * [Date1, DateN] - cached (all/between)
  2311. */
  2312. Cache.prototype._cacheGet = function (what, args) {
  2313. var cached = false;
  2314. var argsKeys = args ? Object.keys(args) : [];
  2315. var findCacheDiff = function (item) {
  2316. for (var i = 0; i < argsKeys.length; i++) {
  2317. var key = argsKeys[i];
  2318. if (String(args[key]) !== String(item[key])) {
  2319. return true;
  2320. }
  2321. }
  2322. return false;
  2323. };
  2324. var cachedObject = this[what];
  2325. if (what === 'all') {
  2326. cached = this.all;
  2327. }
  2328. else if (isArray(cachedObject)) {
  2329. // Let's see whether we've already called the
  2330. // 'what' method with the same 'args'
  2331. for (var i = 0; i < cachedObject.length; i++) {
  2332. var item = cachedObject[i];
  2333. if (argsKeys.length && findCacheDiff(item))
  2334. continue;
  2335. cached = item._value;
  2336. break;
  2337. }
  2338. }
  2339. if (!cached && this.all) {
  2340. // Not in the cache, but we already know all the occurrences,
  2341. // so we can find the correct dates from the cached ones.
  2342. var iterResult = new iterresult(what, args);
  2343. for (var i = 0; i < this.all.length; i++) {
  2344. if (!iterResult.accept(this.all[i]))
  2345. break;
  2346. }
  2347. cached = iterResult.getValue();
  2348. this._cacheAdd(what, cached, args);
  2349. }
  2350. return isArray(cached)
  2351. ? src_dateutil.cloneDates(cached)
  2352. : cached instanceof Date
  2353. ? src_dateutil.clone(cached)
  2354. : cached;
  2355. };
  2356. return Cache;
  2357. }());
  2358. // CONCATENATED MODULE: ./src/masks.ts
  2359. // =============================================================================
  2360. // Date masks
  2361. // =============================================================================
  2362. // Every mask is 7 days longer to handle cross-year weekly periods.
  2363. var M365MASK = __spreadArrays(repeat(1, 31), repeat(2, 28), repeat(3, 31), repeat(4, 30), repeat(5, 31), repeat(6, 30), repeat(7, 31), repeat(8, 31), repeat(9, 30), repeat(10, 31), repeat(11, 30), repeat(12, 31), repeat(1, 7));
  2364. var M366MASK = __spreadArrays(repeat(1, 31), repeat(2, 29), repeat(3, 31), repeat(4, 30), repeat(5, 31), repeat(6, 30), repeat(7, 31), repeat(8, 31), repeat(9, 30), repeat(10, 31), repeat(11, 30), repeat(12, 31), repeat(1, 7));
  2365. var M28 = range(1, 29);
  2366. var M29 = range(1, 30);
  2367. var M30 = range(1, 31);
  2368. var M31 = range(1, 32);
  2369. var MDAY366MASK = __spreadArrays(M31, M29, M31, M30, M31, M30, M31, M31, M30, M31, M30, M31, M31.slice(0, 7));
  2370. var MDAY365MASK = __spreadArrays(M31, M28, M31, M30, M31, M30, M31, M31, M30, M31, M30, M31, M31.slice(0, 7));
  2371. var NM28 = range(-28, 0);
  2372. var NM29 = range(-29, 0);
  2373. var NM30 = range(-30, 0);
  2374. var NM31 = range(-31, 0);
  2375. var NMDAY366MASK = __spreadArrays(NM31, NM29, NM31, NM30, NM31, NM30, NM31, NM31, NM30, NM31, NM30, NM31, NM31.slice(0, 7));
  2376. var NMDAY365MASK = __spreadArrays(NM31, NM28, NM31, NM30, NM31, NM30, NM31, NM31, NM30, NM31, NM30, NM31, NM31.slice(0, 7));
  2377. var M366RANGE = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366];
  2378. var M365RANGE = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
  2379. var WDAYMASK = (function () {
  2380. var wdaymask = [];
  2381. for (var i = 0; i < 55; i++)
  2382. wdaymask = wdaymask.concat(range(7));
  2383. return wdaymask;
  2384. })();
  2385. // CONCATENATED MODULE: ./src/iterinfo/yearinfo.ts
  2386. function rebuildYear(year, options) {
  2387. var firstyday = new Date(Date.UTC(year, 0, 1));
  2388. var yearlen = src_dateutil.isLeapYear(year) ? 366 : 365;
  2389. var nextyearlen = src_dateutil.isLeapYear(year + 1) ? 366 : 365;
  2390. var yearordinal = src_dateutil.toOrdinal(firstyday);
  2391. var yearweekday = src_dateutil.getWeekday(firstyday);
  2392. var result = __assign(__assign({ yearlen: yearlen,
  2393. nextyearlen: nextyearlen,
  2394. yearordinal: yearordinal,
  2395. yearweekday: yearweekday }, baseYearMasks(year)), { wnomask: null });
  2396. if (empty(options.byweekno)) {
  2397. return result;
  2398. }
  2399. result.wnomask = repeat(0, yearlen + 7);
  2400. var firstwkst;
  2401. var wyearlen;
  2402. var no1wkst = firstwkst = pymod(7 - yearweekday + options.wkst, 7);
  2403. if (no1wkst >= 4) {
  2404. no1wkst = 0;
  2405. // Number of days in the year, plus the days we got
  2406. // from last year.
  2407. wyearlen =
  2408. result.yearlen + pymod(yearweekday - options.wkst, 7);
  2409. }
  2410. else {
  2411. // Number of days in the year, minus the days we
  2412. // left in last year.
  2413. wyearlen = yearlen - no1wkst;
  2414. }
  2415. var div = Math.floor(wyearlen / 7);
  2416. var mod = pymod(wyearlen, 7);
  2417. var numweeks = Math.floor(div + mod / 4);
  2418. for (var j = 0; j < options.byweekno.length; j++) {
  2419. var n = options.byweekno[j];
  2420. if (n < 0) {
  2421. n += numweeks + 1;
  2422. }
  2423. if (!(n > 0 && n <= numweeks)) {
  2424. continue;
  2425. }
  2426. var i = void 0;
  2427. if (n > 1) {
  2428. i = no1wkst + (n - 1) * 7;
  2429. if (no1wkst !== firstwkst) {
  2430. i -= 7 - firstwkst;
  2431. }
  2432. }
  2433. else {
  2434. i = no1wkst;
  2435. }
  2436. for (var k = 0; k < 7; k++) {
  2437. result.wnomask[i] = 1;
  2438. i++;
  2439. if (result.wdaymask[i] === options.wkst)
  2440. break;
  2441. }
  2442. }
  2443. if (includes(options.byweekno, 1)) {
  2444. // Check week number 1 of next year as well
  2445. // orig-TODO : Check -numweeks for next year.
  2446. var i = no1wkst + numweeks * 7;
  2447. if (no1wkst !== firstwkst)
  2448. i -= 7 - firstwkst;
  2449. if (i < yearlen) {
  2450. // If week starts in next year, we
  2451. // don't care about it.
  2452. for (var j = 0; j < 7; j++) {
  2453. result.wnomask[i] = 1;
  2454. i += 1;
  2455. if (result.wdaymask[i] === options.wkst)
  2456. break;
  2457. }
  2458. }
  2459. }
  2460. if (no1wkst) {
  2461. // Check last week number of last year as
  2462. // well. If no1wkst is 0, either the year
  2463. // started on week start, or week number 1
  2464. // got days from last year, so there are no
  2465. // days from last year's last week number in
  2466. // this year.
  2467. var lnumweeks = void 0;
  2468. if (!includes(options.byweekno, -1)) {
  2469. var lyearweekday = src_dateutil.getWeekday(new Date(Date.UTC(year - 1, 0, 1)));
  2470. var lno1wkst = pymod(7 - lyearweekday.valueOf() + options.wkst, 7);
  2471. var lyearlen = src_dateutil.isLeapYear(year - 1) ? 366 : 365;
  2472. var weekst = void 0;
  2473. if (lno1wkst >= 4) {
  2474. lno1wkst = 0;
  2475. weekst = lyearlen + pymod(lyearweekday - options.wkst, 7);
  2476. }
  2477. else {
  2478. weekst = yearlen - no1wkst;
  2479. }
  2480. lnumweeks = Math.floor(52 + pymod(weekst, 7) / 4);
  2481. }
  2482. else {
  2483. lnumweeks = -1;
  2484. }
  2485. if (includes(options.byweekno, lnumweeks)) {
  2486. for (var i = 0; i < no1wkst; i++)
  2487. result.wnomask[i] = 1;
  2488. }
  2489. }
  2490. return result;
  2491. }
  2492. function baseYearMasks(year) {
  2493. var yearlen = src_dateutil.isLeapYear(year) ? 366 : 365;
  2494. var firstyday = new Date(Date.UTC(year, 0, 1));
  2495. var wday = src_dateutil.getWeekday(firstyday);
  2496. if (yearlen === 365) {
  2497. return {
  2498. mmask: M365MASK,
  2499. mdaymask: MDAY365MASK,
  2500. nmdaymask: NMDAY365MASK,
  2501. wdaymask: WDAYMASK.slice(wday),
  2502. mrange: M365RANGE
  2503. };
  2504. }
  2505. return {
  2506. mmask: M366MASK,
  2507. mdaymask: MDAY366MASK,
  2508. nmdaymask: NMDAY366MASK,
  2509. wdaymask: WDAYMASK.slice(wday),
  2510. mrange: M366RANGE
  2511. };
  2512. }
  2513. // CONCATENATED MODULE: ./src/iterinfo/monthinfo.ts
  2514. function rebuildMonth(year, month, yearlen, mrange, wdaymask, options) {
  2515. var result = {
  2516. lastyear: year,
  2517. lastmonth: month,
  2518. nwdaymask: []
  2519. };
  2520. var ranges = [];
  2521. if (options.freq === src_rrule.YEARLY) {
  2522. if (empty(options.bymonth)) {
  2523. ranges = [[0, yearlen]];
  2524. }
  2525. else {
  2526. for (var j = 0; j < options.bymonth.length; j++) {
  2527. month = options.bymonth[j];
  2528. ranges.push(mrange.slice(month - 1, month + 1));
  2529. }
  2530. }
  2531. }
  2532. else if (options.freq === src_rrule.MONTHLY) {
  2533. ranges = [mrange.slice(month - 1, month + 1)];
  2534. }
  2535. if (empty(ranges)) {
  2536. return result;
  2537. }
  2538. // Weekly frequency won't get here, so we may not
  2539. // care about cross-year weekly periods.
  2540. result.nwdaymask = repeat(0, yearlen);
  2541. for (var j = 0; j < ranges.length; j++) {
  2542. var rang = ranges[j];
  2543. var first = rang[0];
  2544. var last = rang[1] - 1;
  2545. for (var k = 0; k < options.bynweekday.length; k++) {
  2546. var i = void 0;
  2547. var _a = options.bynweekday[k], wday = _a[0], n = _a[1];
  2548. if (n < 0) {
  2549. i = last + (n + 1) * 7;
  2550. i -= pymod(wdaymask[i] - wday, 7);
  2551. }
  2552. else {
  2553. i = first + (n - 1) * 7;
  2554. i += pymod(7 - wdaymask[i] + wday, 7);
  2555. }
  2556. if (first <= i && i <= last)
  2557. result.nwdaymask[i] = 1;
  2558. }
  2559. }
  2560. return result;
  2561. }
  2562. // CONCATENATED MODULE: ./src/iterinfo/easter.ts
  2563. function easter(y, offset) {
  2564. if (offset === void 0) { offset = 0; }
  2565. var a = y % 19;
  2566. var b = Math.floor(y / 100);
  2567. var c = y % 100;
  2568. var d = Math.floor(b / 4);
  2569. var e = b % 4;
  2570. var f = Math.floor((b + 8) / 25);
  2571. var g = Math.floor((b - f + 1) / 3);
  2572. var h = Math.floor(19 * a + b - d - g + 15) % 30;
  2573. var i = Math.floor(c / 4);
  2574. var k = c % 4;
  2575. var l = Math.floor(32 + 2 * e + 2 * i - h - k) % 7;
  2576. var m = Math.floor((a + 11 * h + 22 * l) / 451);
  2577. var month = Math.floor((h + l - 7 * m + 114) / 31);
  2578. var day = ((h + l - 7 * m + 114) % 31) + 1;
  2579. var date = Date.UTC(y, month - 1, day + offset);
  2580. var yearStart = Date.UTC(y, 0, 1);
  2581. return [Math.ceil((date - yearStart) / (1000 * 60 * 60 * 24))];
  2582. }
  2583. // CONCATENATED MODULE: ./src/iterinfo/index.ts
  2584. // =============================================================================
  2585. // Iterinfo
  2586. // =============================================================================
  2587. var iterinfo_Iterinfo = /** @class */ (function () {
  2588. function Iterinfo(options) {
  2589. this.options = options;
  2590. }
  2591. Iterinfo.prototype.rebuild = function (year, month) {
  2592. var options = this.options;
  2593. if (year !== this.lastyear) {
  2594. this.yearinfo = rebuildYear(year, options);
  2595. }
  2596. if (notEmpty(options.bynweekday) &&
  2597. (month !== this.lastmonth || year !== this.lastyear)) {
  2598. var _a = this.yearinfo, yearlen = _a.yearlen, mrange = _a.mrange, wdaymask = _a.wdaymask;
  2599. this.monthinfo = rebuildMonth(year, month, yearlen, mrange, wdaymask, options);
  2600. }
  2601. if (isPresent(options.byeaster)) {
  2602. this.eastermask = easter(year, options.byeaster);
  2603. }
  2604. };
  2605. Object.defineProperty(Iterinfo.prototype, "lastyear", {
  2606. get: function () {
  2607. return this.monthinfo ? this.monthinfo.lastyear : null;
  2608. },
  2609. enumerable: true,
  2610. configurable: true
  2611. });
  2612. Object.defineProperty(Iterinfo.prototype, "lastmonth", {
  2613. get: function () {
  2614. return this.monthinfo ? this.monthinfo.lastmonth : null;
  2615. },
  2616. enumerable: true,
  2617. configurable: true
  2618. });
  2619. Object.defineProperty(Iterinfo.prototype, "yearlen", {
  2620. get: function () {
  2621. return this.yearinfo.yearlen;
  2622. },
  2623. enumerable: true,
  2624. configurable: true
  2625. });
  2626. Object.defineProperty(Iterinfo.prototype, "yearordinal", {
  2627. get: function () {
  2628. return this.yearinfo.yearordinal;
  2629. },
  2630. enumerable: true,
  2631. configurable: true
  2632. });
  2633. Object.defineProperty(Iterinfo.prototype, "mrange", {
  2634. get: function () {
  2635. return this.yearinfo.mrange;
  2636. },
  2637. enumerable: true,
  2638. configurable: true
  2639. });
  2640. Object.defineProperty(Iterinfo.prototype, "wdaymask", {
  2641. get: function () {
  2642. return this.yearinfo.wdaymask;
  2643. },
  2644. enumerable: true,
  2645. configurable: true
  2646. });
  2647. Object.defineProperty(Iterinfo.prototype, "mmask", {
  2648. get: function () {
  2649. return this.yearinfo.mmask;
  2650. },
  2651. enumerable: true,
  2652. configurable: true
  2653. });
  2654. Object.defineProperty(Iterinfo.prototype, "wnomask", {
  2655. get: function () {
  2656. return this.yearinfo.wnomask;
  2657. },
  2658. enumerable: true,
  2659. configurable: true
  2660. });
  2661. Object.defineProperty(Iterinfo.prototype, "nwdaymask", {
  2662. get: function () {
  2663. return this.monthinfo ? this.monthinfo.nwdaymask : [];
  2664. },
  2665. enumerable: true,
  2666. configurable: true
  2667. });
  2668. Object.defineProperty(Iterinfo.prototype, "nextyearlen", {
  2669. get: function () {
  2670. return this.yearinfo.nextyearlen;
  2671. },
  2672. enumerable: true,
  2673. configurable: true
  2674. });
  2675. Object.defineProperty(Iterinfo.prototype, "mdaymask", {
  2676. get: function () {
  2677. return this.yearinfo.mdaymask;
  2678. },
  2679. enumerable: true,
  2680. configurable: true
  2681. });
  2682. Object.defineProperty(Iterinfo.prototype, "nmdaymask", {
  2683. get: function () {
  2684. return this.yearinfo.nmdaymask;
  2685. },
  2686. enumerable: true,
  2687. configurable: true
  2688. });
  2689. Iterinfo.prototype.ydayset = function () {
  2690. return [range(this.yearlen), 0, this.yearlen];
  2691. };
  2692. Iterinfo.prototype.mdayset = function (_, month, __) {
  2693. var start = this.mrange[month - 1];
  2694. var end = this.mrange[month];
  2695. var set = repeat(null, this.yearlen);
  2696. for (var i = start; i < end; i++)
  2697. set[i] = i;
  2698. return [set, start, end];
  2699. };
  2700. Iterinfo.prototype.wdayset = function (year, month, day) {
  2701. // We need to handle cross-year weeks here.
  2702. var set = repeat(null, this.yearlen + 7);
  2703. var i = src_dateutil.toOrdinal(new Date(Date.UTC(year, month - 1, day))) -
  2704. this.yearordinal;
  2705. var start = i;
  2706. for (var j = 0; j < 7; j++) {
  2707. set[i] = i;
  2708. ++i;
  2709. if (this.wdaymask[i] === this.options.wkst)
  2710. break;
  2711. }
  2712. return [set, start, i];
  2713. };
  2714. Iterinfo.prototype.ddayset = function (year, month, day) {
  2715. var set = repeat(null, this.yearlen);
  2716. var i = src_dateutil.toOrdinal(new Date(Date.UTC(year, month - 1, day))) -
  2717. this.yearordinal;
  2718. set[i] = i;
  2719. return [set, i, i + 1];
  2720. };
  2721. Iterinfo.prototype.htimeset = function (hour, _, second, millisecond) {
  2722. var _this = this;
  2723. var set = [];
  2724. this.options.byminute.forEach(function (minute) {
  2725. set = set.concat(_this.mtimeset(hour, minute, second, millisecond));
  2726. });
  2727. src_dateutil.sort(set);
  2728. return set;
  2729. };
  2730. Iterinfo.prototype.mtimeset = function (hour, minute, _, millisecond) {
  2731. var set = this.options.bysecond.map(function (second) {
  2732. return new Time(hour, minute, second, millisecond);
  2733. });
  2734. src_dateutil.sort(set);
  2735. return set;
  2736. };
  2737. Iterinfo.prototype.stimeset = function (hour, minute, second, millisecond) {
  2738. return [new Time(hour, minute, second, millisecond)];
  2739. };
  2740. Iterinfo.prototype.getdayset = function (freq) {
  2741. switch (freq) {
  2742. case Frequency.YEARLY: return this.ydayset.bind(this);
  2743. case Frequency.MONTHLY: return this.mdayset.bind(this);
  2744. case Frequency.WEEKLY: return this.wdayset.bind(this);
  2745. case Frequency.DAILY: return this.ddayset.bind(this);
  2746. default: return this.ddayset.bind(this);
  2747. }
  2748. };
  2749. Iterinfo.prototype.gettimeset = function (freq) {
  2750. switch (freq) {
  2751. case Frequency.HOURLY: return this.htimeset.bind(this);
  2752. case Frequency.MINUTELY: return this.mtimeset.bind(this);
  2753. case Frequency.SECONDLY: return this.stimeset.bind(this);
  2754. }
  2755. };
  2756. return Iterinfo;
  2757. }());
  2758. /* harmony default export */ var iterinfo = (iterinfo_Iterinfo);
  2759. // CONCATENATED MODULE: ./src/iter/poslist.ts
  2760. function buildPoslist(bysetpos, timeset, start, end, ii, dayset) {
  2761. var poslist = [];
  2762. for (var j = 0; j < bysetpos.length; j++) {
  2763. var daypos = void 0;
  2764. var timepos = void 0;
  2765. var pos = bysetpos[j];
  2766. if (pos < 0) {
  2767. daypos = Math.floor(pos / timeset.length);
  2768. timepos = pymod(pos, timeset.length);
  2769. }
  2770. else {
  2771. daypos = Math.floor((pos - 1) / timeset.length);
  2772. timepos = pymod(pos - 1, timeset.length);
  2773. }
  2774. var tmp = [];
  2775. for (var k = start; k < end; k++) {
  2776. var val = dayset[k];
  2777. if (!isPresent(val))
  2778. continue;
  2779. tmp.push(val);
  2780. }
  2781. var i = void 0;
  2782. if (daypos < 0) {
  2783. i = tmp.slice(daypos)[0];
  2784. }
  2785. else {
  2786. i = tmp[daypos];
  2787. }
  2788. var time = timeset[timepos];
  2789. var date = src_dateutil.fromOrdinal(ii.yearordinal + i);
  2790. var res = src_dateutil.combine(date, time);
  2791. // XXX: can this ever be in the array?
  2792. // - compare the actual date instead?
  2793. if (!includes(poslist, res))
  2794. poslist.push(res);
  2795. }
  2796. src_dateutil.sort(poslist);
  2797. return poslist;
  2798. }
  2799. // CONCATENATED MODULE: ./src/iter/index.ts
  2800. function iter(iterResult, options) {
  2801. var dtstart = options.dtstart, freq = options.freq, interval = options.interval, until = options.until, bysetpos = options.bysetpos;
  2802. var count = options.count;
  2803. if (count === 0 || interval === 0) {
  2804. return emitResult(iterResult);
  2805. }
  2806. var counterDate = datetime_DateTime.fromDate(dtstart);
  2807. var ii = new iterinfo(options);
  2808. ii.rebuild(counterDate.year, counterDate.month);
  2809. var timeset = makeTimeset(ii, counterDate, options);
  2810. while (true) {
  2811. var _a = ii.getdayset(freq)(counterDate.year, counterDate.month, counterDate.day), dayset = _a[0], start = _a[1], end = _a[2];
  2812. var filtered = removeFilteredDays(dayset, start, end, ii, options);
  2813. if (notEmpty(bysetpos)) {
  2814. var poslist = buildPoslist(bysetpos, timeset, start, end, ii, dayset);
  2815. for (var j = 0; j < poslist.length; j++) {
  2816. var res = poslist[j];
  2817. if (until && res > until) {
  2818. return emitResult(iterResult);
  2819. }
  2820. if (res >= dtstart) {
  2821. var rezonedDate = rezoneIfNeeded(res, options);
  2822. if (!iterResult.accept(rezonedDate)) {
  2823. return emitResult(iterResult);
  2824. }
  2825. if (count) {
  2826. --count;
  2827. if (!count) {
  2828. return emitResult(iterResult);
  2829. }
  2830. }
  2831. }
  2832. }
  2833. }
  2834. else {
  2835. for (var j = start; j < end; j++) {
  2836. var currentDay = dayset[j];
  2837. if (!isPresent(currentDay)) {
  2838. continue;
  2839. }
  2840. var date = src_dateutil.fromOrdinal(ii.yearordinal + currentDay);
  2841. for (var k = 0; k < timeset.length; k++) {
  2842. var time = timeset[k];
  2843. var res = src_dateutil.combine(date, time);
  2844. if (until && res > until) {
  2845. return emitResult(iterResult);
  2846. }
  2847. if (res >= dtstart) {
  2848. var rezonedDate = rezoneIfNeeded(res, options);
  2849. if (!iterResult.accept(rezonedDate)) {
  2850. return emitResult(iterResult);
  2851. }
  2852. if (count) {
  2853. --count;
  2854. if (!count) {
  2855. return emitResult(iterResult);
  2856. }
  2857. }
  2858. }
  2859. }
  2860. }
  2861. }
  2862. if (options.interval === 0) {
  2863. return emitResult(iterResult);
  2864. }
  2865. // Handle frequency and interval
  2866. counterDate.add(options, filtered);
  2867. if (counterDate.year > src_dateutil.MAXYEAR) {
  2868. return emitResult(iterResult);
  2869. }
  2870. if (!freqIsDailyOrGreater(freq)) {
  2871. timeset = ii.gettimeset(freq)(counterDate.hour, counterDate.minute, counterDate.second, 0);
  2872. }
  2873. ii.rebuild(counterDate.year, counterDate.month);
  2874. }
  2875. }
  2876. function isFiltered(ii, currentDay, options) {
  2877. var bymonth = options.bymonth, byweekno = options.byweekno, byweekday = options.byweekday, byeaster = options.byeaster, bymonthday = options.bymonthday, bynmonthday = options.bynmonthday, byyearday = options.byyearday;
  2878. return ((notEmpty(bymonth) && !includes(bymonth, ii.mmask[currentDay])) ||
  2879. (notEmpty(byweekno) && !ii.wnomask[currentDay]) ||
  2880. (notEmpty(byweekday) && !includes(byweekday, ii.wdaymask[currentDay])) ||
  2881. (notEmpty(ii.nwdaymask) && !ii.nwdaymask[currentDay]) ||
  2882. (byeaster !== null && !includes(ii.eastermask, currentDay)) ||
  2883. ((notEmpty(bymonthday) || notEmpty(bynmonthday)) &&
  2884. !includes(bymonthday, ii.mdaymask[currentDay]) &&
  2885. !includes(bynmonthday, ii.nmdaymask[currentDay])) ||
  2886. (notEmpty(byyearday) &&
  2887. ((currentDay < ii.yearlen &&
  2888. !includes(byyearday, currentDay + 1) &&
  2889. !includes(byyearday, -ii.yearlen + currentDay)) ||
  2890. (currentDay >= ii.yearlen &&
  2891. !includes(byyearday, currentDay + 1 - ii.yearlen) &&
  2892. !includes(byyearday, -ii.nextyearlen + currentDay - ii.yearlen)))));
  2893. }
  2894. function rezoneIfNeeded(date, options) {
  2895. return new datewithzone_DateWithZone(date, options.tzid).rezonedDate();
  2896. }
  2897. function emitResult(iterResult) {
  2898. return iterResult.getValue();
  2899. }
  2900. function removeFilteredDays(dayset, start, end, ii, options) {
  2901. var filtered = false;
  2902. for (var dayCounter = start; dayCounter < end; dayCounter++) {
  2903. var currentDay = dayset[dayCounter];
  2904. filtered = isFiltered(ii, currentDay, options);
  2905. if (filtered)
  2906. dayset[currentDay] = null;
  2907. }
  2908. return filtered;
  2909. }
  2910. function makeTimeset(ii, counterDate, options) {
  2911. var freq = options.freq, byhour = options.byhour, byminute = options.byminute, bysecond = options.bysecond;
  2912. if (freqIsDailyOrGreater(freq)) {
  2913. return buildTimeset(options);
  2914. }
  2915. if ((freq >= src_rrule.HOURLY &&
  2916. notEmpty(byhour) &&
  2917. !includes(byhour, counterDate.hour)) ||
  2918. (freq >= src_rrule.MINUTELY &&
  2919. notEmpty(byminute) &&
  2920. !includes(byminute, counterDate.minute)) ||
  2921. (freq >= src_rrule.SECONDLY &&
  2922. notEmpty(bysecond) &&
  2923. !includes(bysecond, counterDate.second))) {
  2924. return [];
  2925. }
  2926. return ii.gettimeset(freq)(counterDate.hour, counterDate.minute, counterDate.second, counterDate.millisecond);
  2927. }
  2928. // CONCATENATED MODULE: ./src/rrule.ts
  2929. // =============================================================================
  2930. // RRule
  2931. // =============================================================================
  2932. var Days = {
  2933. MO: new Weekday(0),
  2934. TU: new Weekday(1),
  2935. WE: new Weekday(2),
  2936. TH: new Weekday(3),
  2937. FR: new Weekday(4),
  2938. SA: new Weekday(5),
  2939. SU: new Weekday(6)
  2940. };
  2941. var DEFAULT_OPTIONS = {
  2942. freq: Frequency.YEARLY,
  2943. dtstart: null,
  2944. interval: 1,
  2945. wkst: Days.MO,
  2946. count: null,
  2947. until: null,
  2948. tzid: null,
  2949. bysetpos: null,
  2950. bymonth: null,
  2951. bymonthday: null,
  2952. bynmonthday: null,
  2953. byyearday: null,
  2954. byweekno: null,
  2955. byweekday: null,
  2956. bynweekday: null,
  2957. byhour: null,
  2958. byminute: null,
  2959. bysecond: null,
  2960. byeaster: null
  2961. };
  2962. var rrule_defaultKeys = Object.keys(DEFAULT_OPTIONS);
  2963. /**
  2964. *
  2965. * @param {Options?} options - see <http://labix.org/python-dateutil/#head-cf004ee9a75592797e076752b2a889c10f445418>
  2966. * The only required option is `freq`, one of RRule.YEARLY, RRule.MONTHLY, ...
  2967. * @constructor
  2968. */
  2969. var rrule_RRule = /** @class */ (function () {
  2970. function RRule(options, noCache) {
  2971. if (options === void 0) { options = {}; }
  2972. if (noCache === void 0) { noCache = false; }
  2973. // RFC string
  2974. this._cache = noCache ? null : new cache_Cache();
  2975. // used by toString()
  2976. this.origOptions = initializeOptions(options);
  2977. var parsedOptions = parseOptions(options).parsedOptions;
  2978. this.options = parsedOptions;
  2979. }
  2980. RRule.parseText = function (text, language) {
  2981. return parseText(text, language);
  2982. };
  2983. RRule.fromText = function (text, language) {
  2984. return fromText(text, language);
  2985. };
  2986. RRule.fromString = function (str) {
  2987. return new RRule(RRule.parseString(str) || undefined);
  2988. };
  2989. RRule.prototype._iter = function (iterResult) {
  2990. return iter(iterResult, this.options);
  2991. };
  2992. RRule.prototype._cacheGet = function (what, args) {
  2993. if (!this._cache)
  2994. return false;
  2995. return this._cache._cacheGet(what, args);
  2996. };
  2997. RRule.prototype._cacheAdd = function (what, value, args) {
  2998. if (!this._cache)
  2999. return;
  3000. return this._cache._cacheAdd(what, value, args);
  3001. };
  3002. /**
  3003. * @param {Function} iterator - optional function that will be called
  3004. * on each date that is added. It can return false
  3005. * to stop the iteration.
  3006. * @return Array containing all recurrences.
  3007. */
  3008. RRule.prototype.all = function (iterator) {
  3009. if (iterator) {
  3010. return this._iter(new callbackiterresult('all', {}, iterator));
  3011. }
  3012. var result = this._cacheGet('all');
  3013. if (result === false) {
  3014. result = this._iter(new iterresult('all', {}));
  3015. this._cacheAdd('all', result);
  3016. }
  3017. return result;
  3018. };
  3019. /**
  3020. * Returns all the occurrences of the rrule between after and before.
  3021. * The inc keyword defines what happens if after and/or before are
  3022. * themselves occurrences. With inc == True, they will be included in the
  3023. * list, if they are found in the recurrence set.
  3024. * @return Array
  3025. */
  3026. RRule.prototype.between = function (after, before, inc, iterator) {
  3027. if (inc === void 0) { inc = false; }
  3028. if (!src_dateutil.isValidDate(after) || !src_dateutil.isValidDate(before))
  3029. throw new Error('Invalid date passed in to RRule.between');
  3030. var args = {
  3031. before: before,
  3032. after: after,
  3033. inc: inc
  3034. };
  3035. if (iterator) {
  3036. return this._iter(new callbackiterresult('between', args, iterator));
  3037. }
  3038. var result = this._cacheGet('between', args);
  3039. if (result === false) {
  3040. result = this._iter(new iterresult('between', args));
  3041. this._cacheAdd('between', result, args);
  3042. }
  3043. return result;
  3044. };
  3045. /**
  3046. * Returns the last recurrence before the given datetime instance.
  3047. * The inc keyword defines what happens if dt is an occurrence.
  3048. * With inc == True, if dt itself is an occurrence, it will be returned.
  3049. * @return Date or null
  3050. */
  3051. RRule.prototype.before = function (dt, inc) {
  3052. if (inc === void 0) { inc = false; }
  3053. if (!src_dateutil.isValidDate(dt))
  3054. throw new Error('Invalid date passed in to RRule.before');
  3055. var args = { dt: dt, inc: inc };
  3056. var result = this._cacheGet('before', args);
  3057. if (result === false) {
  3058. result = this._iter(new iterresult('before', args));
  3059. this._cacheAdd('before', result, args);
  3060. }
  3061. return result;
  3062. };
  3063. /**
  3064. * Returns the first recurrence after the given datetime instance.
  3065. * The inc keyword defines what happens if dt is an occurrence.
  3066. * With inc == True, if dt itself is an occurrence, it will be returned.
  3067. * @return Date or null
  3068. */
  3069. RRule.prototype.after = function (dt, inc) {
  3070. if (inc === void 0) { inc = false; }
  3071. if (!src_dateutil.isValidDate(dt))
  3072. throw new Error('Invalid date passed in to RRule.after');
  3073. var args = { dt: dt, inc: inc };
  3074. var result = this._cacheGet('after', args);
  3075. if (result === false) {
  3076. result = this._iter(new iterresult('after', args));
  3077. this._cacheAdd('after', result, args);
  3078. }
  3079. return result;
  3080. };
  3081. /**
  3082. * Returns the number of recurrences in this set. It will have go trough
  3083. * the whole recurrence, if this hasn't been done before.
  3084. */
  3085. RRule.prototype.count = function () {
  3086. return this.all().length;
  3087. };
  3088. /**
  3089. * Converts the rrule into its string representation
  3090. * @see <http://www.ietf.org/rfc/rfc2445.txt>
  3091. * @return String
  3092. */
  3093. RRule.prototype.toString = function () {
  3094. return optionsToString(this.origOptions);
  3095. };
  3096. /**
  3097. * Will convert all rules described in nlp:ToText
  3098. * to text.
  3099. */
  3100. RRule.prototype.toText = function (gettext, language, dateFormatter) {
  3101. return toText(this, gettext, language, dateFormatter);
  3102. };
  3103. RRule.prototype.isFullyConvertibleToText = function () {
  3104. return isFullyConvertible(this);
  3105. };
  3106. /**
  3107. * @return a RRule instance with the same freq and options
  3108. * as this one (cache is not cloned)
  3109. */
  3110. RRule.prototype.clone = function () {
  3111. return new RRule(this.origOptions);
  3112. };
  3113. // RRule class 'constants'
  3114. RRule.FREQUENCIES = [
  3115. 'YEARLY',
  3116. 'MONTHLY',
  3117. 'WEEKLY',
  3118. 'DAILY',
  3119. 'HOURLY',
  3120. 'MINUTELY',
  3121. 'SECONDLY'
  3122. ];
  3123. RRule.YEARLY = Frequency.YEARLY;
  3124. RRule.MONTHLY = Frequency.MONTHLY;
  3125. RRule.WEEKLY = Frequency.WEEKLY;
  3126. RRule.DAILY = Frequency.DAILY;
  3127. RRule.HOURLY = Frequency.HOURLY;
  3128. RRule.MINUTELY = Frequency.MINUTELY;
  3129. RRule.SECONDLY = Frequency.SECONDLY;
  3130. RRule.MO = Days.MO;
  3131. RRule.TU = Days.TU;
  3132. RRule.WE = Days.WE;
  3133. RRule.TH = Days.TH;
  3134. RRule.FR = Days.FR;
  3135. RRule.SA = Days.SA;
  3136. RRule.SU = Days.SU;
  3137. RRule.parseString = parseString;
  3138. RRule.optionsToString = optionsToString;
  3139. return RRule;
  3140. }());
  3141. /* harmony default export */ var src_rrule = (rrule_RRule);
  3142. // CONCATENATED MODULE: ./src/iterset.ts
  3143. function iterSet(iterResult, _rrule, _exrule, _rdate, _exdate, tzid) {
  3144. var _exdateHash = {};
  3145. var _accept = iterResult.accept;
  3146. function evalExdate(after, before) {
  3147. _exrule.forEach(function (rrule) {
  3148. rrule.between(after, before, true).forEach(function (date) {
  3149. _exdateHash[Number(date)] = true;
  3150. });
  3151. });
  3152. }
  3153. _exdate.forEach(function (date) {
  3154. var zonedDate = new datewithzone_DateWithZone(date, tzid).rezonedDate();
  3155. _exdateHash[Number(zonedDate)] = true;
  3156. });
  3157. iterResult.accept = function (date) {
  3158. var dt = Number(date);
  3159. if (isNaN(dt))
  3160. return _accept.call(this, date);
  3161. if (!_exdateHash[dt]) {
  3162. evalExdate(new Date(dt - 1), new Date(dt + 1));
  3163. if (!_exdateHash[dt]) {
  3164. _exdateHash[dt] = true;
  3165. return _accept.call(this, date);
  3166. }
  3167. }
  3168. return true;
  3169. };
  3170. if (iterResult.method === 'between') {
  3171. evalExdate(iterResult.args.after, iterResult.args.before);
  3172. iterResult.accept = function (date) {
  3173. var dt = Number(date);
  3174. if (!_exdateHash[dt]) {
  3175. _exdateHash[dt] = true;
  3176. return _accept.call(this, date);
  3177. }
  3178. return true;
  3179. };
  3180. }
  3181. for (var i = 0; i < _rdate.length; i++) {
  3182. var zonedDate = new datewithzone_DateWithZone(_rdate[i], tzid).rezonedDate();
  3183. if (!iterResult.accept(new Date(zonedDate.getTime())))
  3184. break;
  3185. }
  3186. _rrule.forEach(function (rrule) {
  3187. iter(iterResult, rrule.options);
  3188. });
  3189. var res = iterResult._result;
  3190. src_dateutil.sort(res);
  3191. switch (iterResult.method) {
  3192. case 'all':
  3193. case 'between':
  3194. return res;
  3195. case 'before':
  3196. return ((res.length && res[res.length - 1]) || null);
  3197. case 'after':
  3198. default:
  3199. return ((res.length && res[0]) || null);
  3200. }
  3201. }
  3202. // CONCATENATED MODULE: ./src/rrulestr.ts
  3203. /**
  3204. * RRuleStr
  3205. * To parse a set of rrule strings
  3206. */
  3207. var rrulestr_DEFAULT_OPTIONS = {
  3208. dtstart: null,
  3209. cache: false,
  3210. unfold: false,
  3211. forceset: false,
  3212. compatible: false,
  3213. tzid: null
  3214. };
  3215. function parseInput(s, options) {
  3216. var rrulevals = [];
  3217. var rdatevals = [];
  3218. var exrulevals = [];
  3219. var exdatevals = [];
  3220. var _a = parseDtstart(s), dtstart = _a.dtstart, tzid = _a.tzid;
  3221. var lines = splitIntoLines(s, options.unfold);
  3222. lines.forEach(function (line) {
  3223. if (!line)
  3224. return;
  3225. var _a = breakDownLine(line), name = _a.name, parms = _a.parms, value = _a.value;
  3226. switch (name.toUpperCase()) {
  3227. case 'RRULE':
  3228. if (parms.length) {
  3229. throw new Error("unsupported RRULE parm: " + parms.join(','));
  3230. }
  3231. rrulevals.push(parseString(line));
  3232. break;
  3233. case 'RDATE':
  3234. var _b = /RDATE(?:;TZID=([^:=]+))?/i.exec(line), _ = _b[0], rdateTzid = _b[1];
  3235. if (rdateTzid && !tzid) {
  3236. tzid = rdateTzid;
  3237. }
  3238. rdatevals = rdatevals.concat(parseRDate(value, parms));
  3239. break;
  3240. case 'EXRULE':
  3241. if (parms.length) {
  3242. throw new Error("unsupported EXRULE parm: " + parms.join(','));
  3243. }
  3244. exrulevals.push(parseString(value));
  3245. break;
  3246. case 'EXDATE':
  3247. exdatevals = exdatevals.concat(parseRDate(value, parms));
  3248. break;
  3249. case 'DTSTART':
  3250. break;
  3251. default:
  3252. throw new Error('unsupported property: ' + name);
  3253. }
  3254. });
  3255. return {
  3256. dtstart: dtstart,
  3257. tzid: tzid,
  3258. rrulevals: rrulevals,
  3259. rdatevals: rdatevals,
  3260. exrulevals: exrulevals,
  3261. exdatevals: exdatevals
  3262. };
  3263. }
  3264. function buildRule(s, options) {
  3265. var _a = parseInput(s, options), rrulevals = _a.rrulevals, rdatevals = _a.rdatevals, exrulevals = _a.exrulevals, exdatevals = _a.exdatevals, dtstart = _a.dtstart, tzid = _a.tzid;
  3266. var noCache = options.cache === false;
  3267. if (options.compatible) {
  3268. options.forceset = true;
  3269. options.unfold = true;
  3270. }
  3271. if (options.forceset ||
  3272. rrulevals.length > 1 ||
  3273. rdatevals.length ||
  3274. exrulevals.length ||
  3275. exdatevals.length) {
  3276. var rset_1 = new rruleset(noCache);
  3277. rset_1.dtstart(dtstart);
  3278. rset_1.tzid(tzid || undefined);
  3279. rrulevals.forEach(function (val) {
  3280. rset_1.rrule(new src_rrule(groomRruleOptions(val, dtstart, tzid), noCache));
  3281. });
  3282. rdatevals.forEach(function (date) {
  3283. rset_1.rdate(date);
  3284. });
  3285. exrulevals.forEach(function (val) {
  3286. rset_1.exrule(new src_rrule(groomRruleOptions(val, dtstart, tzid), noCache));
  3287. });
  3288. exdatevals.forEach(function (date) {
  3289. rset_1.exdate(date);
  3290. });
  3291. if (options.compatible && options.dtstart)
  3292. rset_1.rdate(dtstart);
  3293. return rset_1;
  3294. }
  3295. var val = rrulevals[0] || {};
  3296. return new src_rrule(groomRruleOptions(val, val.dtstart || options.dtstart || dtstart, val.tzid || options.tzid || tzid), noCache);
  3297. }
  3298. function rrulestr(s, options) {
  3299. if (options === void 0) { options = {}; }
  3300. return buildRule(s, rrulestr_initializeOptions(options));
  3301. }
  3302. function groomRruleOptions(val, dtstart, tzid) {
  3303. return __assign(__assign({}, val), { dtstart: dtstart,
  3304. tzid: tzid });
  3305. }
  3306. function rrulestr_initializeOptions(options) {
  3307. var invalid = [];
  3308. var keys = Object.keys(options);
  3309. var defaultKeys = Object.keys(rrulestr_DEFAULT_OPTIONS);
  3310. keys.forEach(function (key) {
  3311. if (!includes(defaultKeys, key))
  3312. invalid.push(key);
  3313. });
  3314. if (invalid.length) {
  3315. throw new Error('Invalid options: ' + invalid.join(', '));
  3316. }
  3317. return __assign(__assign({}, rrulestr_DEFAULT_OPTIONS), options);
  3318. }
  3319. function extractName(line) {
  3320. if (line.indexOf(':') === -1) {
  3321. return {
  3322. name: 'RRULE',
  3323. value: line
  3324. };
  3325. }
  3326. var _a = split(line, ':', 1), name = _a[0], value = _a[1];
  3327. return {
  3328. name: name,
  3329. value: value
  3330. };
  3331. }
  3332. function breakDownLine(line) {
  3333. var _a = extractName(line), name = _a.name, value = _a.value;
  3334. var parms = name.split(';');
  3335. if (!parms)
  3336. throw new Error('empty property name');
  3337. return {
  3338. name: parms[0].toUpperCase(),
  3339. parms: parms.slice(1),
  3340. value: value
  3341. };
  3342. }
  3343. function splitIntoLines(s, unfold) {
  3344. if (unfold === void 0) { unfold = false; }
  3345. s = s && s.trim();
  3346. if (!s)
  3347. throw new Error('Invalid empty string');
  3348. // More info about 'unfold' option
  3349. // Go head to http://www.ietf.org/rfc/rfc2445.txt
  3350. if (!unfold) {
  3351. return s.split(/\s/);
  3352. }
  3353. var lines = s.split('\n');
  3354. var i = 0;
  3355. while (i < lines.length) {
  3356. // TODO
  3357. var line = (lines[i] = lines[i].replace(/\s+$/g, ''));
  3358. if (!line) {
  3359. lines.splice(i, 1);
  3360. }
  3361. else if (i > 0 && line[0] === ' ') {
  3362. lines[i - 1] += line.slice(1);
  3363. lines.splice(i, 1);
  3364. }
  3365. else {
  3366. i += 1;
  3367. }
  3368. }
  3369. return lines;
  3370. }
  3371. function validateDateParm(parms) {
  3372. parms.forEach(function (parm) {
  3373. if (!/(VALUE=DATE(-TIME)?)|(TZID=)/.test(parm)) {
  3374. throw new Error('unsupported RDATE/EXDATE parm: ' + parm);
  3375. }
  3376. });
  3377. }
  3378. function parseRDate(rdateval, parms) {
  3379. validateDateParm(parms);
  3380. return rdateval
  3381. .split(',')
  3382. .map(function (datestr) { return src_dateutil.untilStringToDate(datestr); });
  3383. }
  3384. // CONCATENATED MODULE: ./src/rruleset.ts
  3385. function createGetterSetter(fieldName) {
  3386. var _this = this;
  3387. return function (field) {
  3388. if (field !== undefined) {
  3389. _this["_" + fieldName] = field;
  3390. }
  3391. if (_this["_" + fieldName] !== undefined) {
  3392. return _this["_" + fieldName];
  3393. }
  3394. for (var i = 0; i < _this._rrule.length; i++) {
  3395. var field_1 = _this._rrule[i].origOptions[fieldName];
  3396. if (field_1) {
  3397. return field_1;
  3398. }
  3399. }
  3400. };
  3401. }
  3402. var rruleset_RRuleSet = /** @class */ (function (_super) {
  3403. __extends(RRuleSet, _super);
  3404. /**
  3405. *
  3406. * @param {Boolean?} noCache
  3407. * The same stratagy as RRule on cache, default to false
  3408. * @constructor
  3409. */
  3410. function RRuleSet(noCache) {
  3411. if (noCache === void 0) { noCache = false; }
  3412. var _this = _super.call(this, {}, noCache) || this;
  3413. _this.dtstart = createGetterSetter.apply(_this, ['dtstart']);
  3414. _this.tzid = createGetterSetter.apply(_this, ['tzid']);
  3415. _this._rrule = [];
  3416. _this._rdate = [];
  3417. _this._exrule = [];
  3418. _this._exdate = [];
  3419. return _this;
  3420. }
  3421. RRuleSet.prototype._iter = function (iterResult) {
  3422. return iterSet(iterResult, this._rrule, this._exrule, this._rdate, this._exdate, this.tzid());
  3423. };
  3424. /**
  3425. * Adds an RRule to the set
  3426. *
  3427. * @param {RRule}
  3428. */
  3429. RRuleSet.prototype.rrule = function (rrule) {
  3430. _addRule(rrule, this._rrule);
  3431. };
  3432. /**
  3433. * Adds an EXRULE to the set
  3434. *
  3435. * @param {RRule}
  3436. */
  3437. RRuleSet.prototype.exrule = function (rrule) {
  3438. _addRule(rrule, this._exrule);
  3439. };
  3440. /**
  3441. * Adds an RDate to the set
  3442. *
  3443. * @param {Date}
  3444. */
  3445. RRuleSet.prototype.rdate = function (date) {
  3446. _addDate(date, this._rdate);
  3447. };
  3448. /**
  3449. * Adds an EXDATE to the set
  3450. *
  3451. * @param {Date}
  3452. */
  3453. RRuleSet.prototype.exdate = function (date) {
  3454. _addDate(date, this._exdate);
  3455. };
  3456. /**
  3457. * Get list of included rrules in this recurrence set.
  3458. *
  3459. * @return List of rrules
  3460. */
  3461. RRuleSet.prototype.rrules = function () {
  3462. return this._rrule.map(function (e) { return rrulestr(e.toString()); });
  3463. };
  3464. /**
  3465. * Get list of excluded rrules in this recurrence set.
  3466. *
  3467. * @return List of exrules
  3468. */
  3469. RRuleSet.prototype.exrules = function () {
  3470. return this._exrule.map(function (e) { return rrulestr(e.toString()); });
  3471. };
  3472. /**
  3473. * Get list of included datetimes in this recurrence set.
  3474. *
  3475. * @return List of rdates
  3476. */
  3477. RRuleSet.prototype.rdates = function () {
  3478. return this._rdate.map(function (e) { return new Date(e.getTime()); });
  3479. };
  3480. /**
  3481. * Get list of included datetimes in this recurrence set.
  3482. *
  3483. * @return List of exdates
  3484. */
  3485. RRuleSet.prototype.exdates = function () {
  3486. return this._exdate.map(function (e) { return new Date(e.getTime()); });
  3487. };
  3488. RRuleSet.prototype.valueOf = function () {
  3489. var result = [];
  3490. if (!this._rrule.length && this._dtstart) {
  3491. result = result.concat(optionsToString({ dtstart: this._dtstart }));
  3492. }
  3493. this._rrule.forEach(function (rrule) {
  3494. result = result.concat(rrule.toString().split('\n'));
  3495. });
  3496. this._exrule.forEach(function (exrule) {
  3497. result = result.concat(exrule.toString().split('\n')
  3498. .map(function (line) { return line.replace(/^RRULE:/, 'EXRULE:'); })
  3499. .filter(function (line) { return !/^DTSTART/.test(line); }));
  3500. });
  3501. if (this._rdate.length) {
  3502. result.push(rdatesToString('RDATE', this._rdate, this.tzid()));
  3503. }
  3504. if (this._exdate.length) {
  3505. result.push(rdatesToString('EXDATE', this._exdate, this.tzid()));
  3506. }
  3507. return result;
  3508. };
  3509. /**
  3510. * to generate recurrence field such as:
  3511. * DTSTART:19970902T010000Z
  3512. * RRULE:FREQ=YEARLY;COUNT=2;BYDAY=TU
  3513. * RRULE:FREQ=YEARLY;COUNT=1;BYDAY=TH
  3514. */
  3515. RRuleSet.prototype.toString = function () {
  3516. return this.valueOf().join('\n');
  3517. };
  3518. /**
  3519. * Create a new RRuleSet Object completely base on current instance
  3520. */
  3521. RRuleSet.prototype.clone = function () {
  3522. var rrs = new RRuleSet(!!this._cache);
  3523. this._rrule.forEach(function (rule) { return rrs.rrule(rule.clone()); });
  3524. this._exrule.forEach(function (rule) { return rrs.exrule(rule.clone()); });
  3525. this._rdate.forEach(function (date) { return rrs.rdate(new Date(date.getTime())); });
  3526. this._exdate.forEach(function (date) { return rrs.exdate(new Date(date.getTime())); });
  3527. return rrs;
  3528. };
  3529. return RRuleSet;
  3530. }(src_rrule));
  3531. /* harmony default export */ var rruleset = (rruleset_RRuleSet);
  3532. function _addRule(rrule, collection) {
  3533. if (!(rrule instanceof src_rrule)) {
  3534. throw new TypeError(String(rrule) + ' is not RRule instance');
  3535. }
  3536. if (!includes(collection.map(String), String(rrule))) {
  3537. collection.push(rrule);
  3538. }
  3539. }
  3540. function _addDate(date, collection) {
  3541. if (!(date instanceof Date)) {
  3542. throw new TypeError(String(date) + ' is not Date instance');
  3543. }
  3544. if (!includes(collection.map(Number), Number(date))) {
  3545. collection.push(date);
  3546. src_dateutil.sort(collection);
  3547. }
  3548. }
  3549. function rdatesToString(param, rdates, tzid) {
  3550. var isUTC = !tzid || tzid.toUpperCase() === 'UTC';
  3551. var header = isUTC ? param + ":" : param + ";TZID=" + tzid + ":";
  3552. var dateString = rdates
  3553. .map(function (rdate) { return src_dateutil.timeToUntilString(rdate.valueOf(), isUTC); })
  3554. .join(',');
  3555. return "" + header + dateString;
  3556. }
  3557. // CONCATENATED MODULE: ./src/index.ts
  3558. /* concated harmony reexport rrulestr */__webpack_require__.d(__webpack_exports__, "rrulestr", function() { return rrulestr; });
  3559. /* concated harmony reexport Frequency */__webpack_require__.d(__webpack_exports__, "Frequency", function() { return Frequency; });
  3560. /* concated harmony reexport Weekday */__webpack_require__.d(__webpack_exports__, "Weekday", function() { return Weekday; });
  3561. /* concated harmony reexport RRule */__webpack_require__.d(__webpack_exports__, "RRule", function() { return src_rrule; });
  3562. /* concated harmony reexport RRuleSet */__webpack_require__.d(__webpack_exports__, "RRuleSet", function() { return rruleset; });
  3563. /*!
  3564. * rrule.js - Library for working with recurrence rules for calendar dates.
  3565. * https://github.com/jakubroztocil/rrule
  3566. *
  3567. * Copyright 2010, Jakub Roztocil and Lars Schoning
  3568. * Licenced under the BSD licence.
  3569. * https://github.com/jakubroztocil/rrule/blob/master/LICENCE
  3570. *
  3571. * Based on:
  3572. * python-dateutil - Extensions to the standard Python datetime module.
  3573. * Copyright (c) 2003-2011 - Gustavo Niemeyer <gustavo@niemeyer.net>
  3574. * Copyright (c) 2012 - Tomi Pieviläinen <tomi.pievilainen@iki.fi>
  3575. * https://github.com/jakubroztocil/rrule/blob/master/LICENCE
  3576. *
  3577. */
  3578. /* harmony default export */ var src = __webpack_exports__["default"] = (src_rrule);
  3579. /***/ })
  3580. /******/ ]);
  3581. });
  3582. //# sourceMappingURL=rrule.js.map