Brak opisu

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