(function(e,t){if(typeof module==="object"&&module.exports){module.exports=t()}else if(typeof define==="function"&&define.amd){define([],t)}else{e.RRule=t(e);e.RRuleSet=e.RRule.RRuleSet;e.rrulestr=e.RRule.rrulestr}})(typeof window==="object"?window:this,function(e){var Z={MONTH_DAYS:[31,28,31,30,31,30,31,31,30,31,30,31],ONE_DAY:1e3*60*60*24,MAXYEAR:9999,ORDINAL_BASE:new Date(1900,0,1),PY_WEEKDAYS:[6,0,1,2,3,4,5],getYearDay:function(e){var t=new Date(e.getFullYear(),e.getMonth(),e.getDate());return Math.ceil((t-new Date(e.getFullYear(),0,1))/Z.ONE_DAY)+1},isLeapYear:function(e){return e%4===0&&e%100!==0||e%400===0},tzOffset:function(e){return e.getTimezoneOffset()*60*1e3},daysBetween:function(e,t){var n=e.getTime()-Z.tzOffset(e);var r=t.getTime()-Z.tzOffset(t);var a=n-r;return Math.round(a/Z.ONE_DAY)},toOrdinal:function(e){if(e0?"+":"")+String(this.n)+e;return e},getJsWeekday:function(){return this.weekday===6?0:this.weekday+1}};var re=function(t,e){t=t||{};this._string=null;this._cache=e?null:{all:false,before:[],after:[],between:[]};this.origOptions={};this.options={};var n=[];var r=Object.keys(t);var a=Object.keys(re.DEFAULT_OPTIONS);r.forEach(function(e){this.origOptions[e]=t[e];this.options[e]=t[e];if(!ne(a,e))n.push(e)},this);if(n.length)throw new Error("Invalid options: "+n.join(", "));if(!re.FREQUENCIES[t.freq]&&t.byeaster===null){throw new Error("Invalid frequency: "+String(t.freq))}a.forEach(function(e){if(!ne(r,e))this.options[e]=re.DEFAULT_OPTIONS[e]},this);var i=this.options;if(i.byeaster!==null)i.freq=re.YEARLY;if(!i.dtstart)i.dtstart=new Date((new Date).setMilliseconds(0));var s=i.dtstart.getTime()%1e3;if(i.wkst===null){i.wkst=re.MO.weekday}else if(typeof i.wkst==="number"){}else{i.wkst=i.wkst.weekday}if(i.bysetpos!==null){if(typeof i.bysetpos==="number")i.bysetpos=[i.bysetpos];for(var o=0;o=-366&&l<=366)){throw new Error("bysetpos must be between 1 and 366,"+" or between -366 and -1")}}}if(!(te(i.byweekno)||te(i.byyearday)||te(i.bymonthday)||i.byweekday!==null||i.byeaster!==null)){switch(i.freq){case re.YEARLY:if(!i.bymonth)i.bymonth=i.dtstart.getMonth()+1;i.bymonthday=i.dtstart.getDate();break;case re.MONTHLY:i.bymonthday=i.dtstart.getDate();break;case re.WEEKLY:i.byweekday=Z.getWeekday(i.dtstart);break}}if(i.bymonth!==null&&!(i.bymonth instanceof Array)){i.bymonth=[i.bymonth]}if(i.byyearday!==null&&!(i.byyearday instanceof Array)){i.byyearday=[i.byyearday]}if(i.bymonthday===null){i.bymonthday=[];i.bynmonthday=[]}else if(i.bymonthday instanceof Array){var f=[];var h=[];for(o=0;o0){f.push(l)}else if(l<0){h.push(l)}}i.bymonthday=f;i.bynmonthday=h}else{if(i.bymonthday<0){i.bynmonthday=[i.bymonthday];i.bymonthday=[]}else{i.bynmonthday=[];i.bymonthday=[i.bymonthday]}}if(i.byweekno!==null&&!(i.byweekno instanceof Array)){i.byweekno=[i.byweekno]}if(i.byweekday===null){i.bynweekday=null}else if(typeof i.byweekday==="number"){i.byweekday=[i.byweekday];i.bynweekday=null}else if(i.byweekday instanceof b){if(!i.byweekday.n||i.freq>re.MONTHLY){i.byweekday=[i.byweekday.weekday];i.bynweekday=null}else{i.bynweekday=[[i.byweekday.weekday,i.byweekday.n]];i.byweekday=null}}else{var u=[];var c=[];for(o=0;ore.MONTHLY){u.push(y.weekday)}else{c.push([y.weekday,y.n])}}i.byweekday=te(u)?u:null;i.bynweekday=te(c)?c:null}if(i.byhour===null){i.byhour=i.freq=re.HOURLY){this.timeset=null}else{this.timeset=[];for(o=0;o=re.HOURLY&&te(E)&&!ne(E,s)||h>=re.MINUTELY&&te(k)&&!ne(k,o)||h>=re.SECONDLY&&te(T)&&!ne(T,l)){R=[]}else{R=O.call(Y,s,o,l,n)}}var A=0;var L=this.options.count;var S,N,U,M,x,I,H,C,B,z,W,F,q;while(true){H=D.call(Y,r,a,i);B=H[0];z=H[1];W=H[2];q=false;for(N=z;N=Y.yearlen&&!ne(w,S+1-Y.yearlen)&&!ne(w,-Y.nextyearlen+S-Y.yearlen));if(q)B[S]=null}if(te(_)&&te(R)){var j,K;var V=[];for(S,N=0;N<_.length;N++){C=_[N];if(C<0){j=Math.floor(C/R.length);K=J(C,R.length)}else{j=Math.floor((C-1)/R.length);K=J(C-1,R.length)}try{H=[];for(U=z;Uy){this._len=A;return e.getValue()}else if(Q>=t){++A;if(!e.accept(Q))return e.getValue();if(L){--L;if(!L){this._len=A;return e.getValue()}}}}}else{for(N=z;Ny){this._len=A;return e.getValue()}else if(Q>=t){++A;if(!e.accept(Q))return e.getValue();if(L){--L;if(!L){this._len=A;return e.getValue()}}}}}}}F=false;if(h===re.YEARLY){r+=u;if(r>Z.MAXYEAR){this._len=A;return e.getValue()}Y.rebuild(r,a)}else if(h===re.MONTHLY){a+=u;if(a>12){x=Math.floor(a/12);I=J(a,12);a=I;r+=x;if(a===0){a=12;--r}if(r>Z.MAXYEAR){this._len=A;return e.getValue()}}Y.rebuild(r,a)}else if(h===re.WEEKLY){if(c>f){i+=-(f+1+(6-c))+u*7}else{i+=-(f-c)+u*7}f=c;F=true}else if(h===re.DAILY){i+=u;F=true}else if(h===re.HOURLY){if(q){s+=Math.floor((23-s)/u)*u}while(true){s+=u;M=ee(s,24);x=M.div;I=M.mod;if(x){s=I;i+=x;F=true}if(!te(E)||ne(E,s))break}R=O.call(Y,s,o,l)}else if(h===re.MINUTELY){if(q){o+=Math.floor((1439-(s*60+o))/u)*u}while(true){o+=u;M=ee(o,60);x=M.div;I=M.mod;if(x){o=I;s+=x;M=ee(s,24);x=M.div;I=M.mod;if(x){s=I;i+=x;F=true;q=false}}if((!te(E)||ne(E,s))&&(!te(k)||ne(k,o))){break}}R=O.call(Y,s,o,l)}else if(h===re.SECONDLY){if(q){l+=Math.floor((86399-(s*3600+o*60+l))/u)*u}while(true){l+=u;M=ee(l,60);x=M.div;I=M.mod;if(x){l=I;o+=x;M=ee(o,60);x=M.div;I=M.mod;if(x){o=I;s+=x;M=ee(s,24);x=M.div;I=M.mod;if(x){s=I;i+=x;F=true}}}if((!te(E)||ne(E,s))&&(!te(k)||ne(k,o))&&(!te(T)||ne(T,l))){break}}R=O.call(Y,s,o,l)}if(F&&i>28){var $=Z.monthRange(r,a-1)[1];if(i>$){while(i>$){i-=$;++a;if(a===13){a=1;++r;if(r>Z.MAXYEAR){this._len=A;return e.getValue()}}$=Z.monthRange(r,a-1)[1]}Y.rebuild(r,a)}}}}};re.parseString=function(e){e=e.replace(/^\s+|\s+$/,"");if(!e.length)return null;var t,n,r,a,i;var s=e.split(";");var o={};for(t=0;t=4){i=0;o=this.yearlen+J(this.yearweekday-n.options.wkst,7)}else{o=this.yearlen-i}var l=Math.floor(o/7);var f=J(o,7);var h=Math.floor(l+f/4);for(var u,c,y=0;y0&&u<=h)){continue}if(u>1){c=i+(u-1)*7;if(i!==s){c-=7-s}}else{c=i}for(var d=0;d<7;d++){this.wnomask[c]=1;c++;if(this.wdaymask[c]===n.options.wkst)break}}if(ne(n.options.byweekno,1)){c=i+h*7;if(i!==s)c-=7-s;if(c=4){v=0;p=Math.floor(52+J(m+J(w-n.options.wkst,7),7)/4)}else{p=Math.floor(52+J(this.yearlen-i,7)/4)}}else{p=-1}if(ne(n.options.byweekno,p)){for(c=0;cthis.maxDate;if(this.method==="between"){if(t)return true;if(n)return false}else if(this.method==="before"){if(n)return false}else if(this.method==="after"){if(t)return true;this.add(e);return false}return this.add(e)},add:function(e){this._result.push(e);return true},getValue:function(){var e=this._result;switch(this.method){case"all":case"between":return e;case"before":case"after":return e.length?e[e.length-1]:null}},clone:function(){return new l(this.method,this.args)}};var o=function(e,t,n){var r=["all","between"];if(!ne(r,e)){throw new Error('Invalid method "'+e+'". Only all and between works with iterator.')}this.add=function(e){if(n(e,this._result.length)){this._result.push(e);return true}return false};this.init(e,t)};o.prototype=l.prototype;var _=function(e){this._cache=e?null:{all:false,before:[],after:[],between:[]};this._rrule=[];this._rdate=[];this._exrule=[];this._exdate=[]};_.prototype={constructor:_,rrule:function(e){if(!(e instanceof re)){throw new TypeError(String(e)+" is not RRule instance")}if(!ne(this._rrule.map(String),String(e))){this._rrule.push(e)}},rdate:function(e){if(!(e instanceof Date)){throw new TypeError(String(e)+" is not Date instance")}if(!ne(this._rdate.map(Number),Number(e))){this._rdate.push(e);Z.sort(this._rdate)}},exrule:function(e){if(!(e instanceof re)){throw new TypeError(String(e)+" is not RRule instance")}if(!ne(this._exrule.map(String),String(e))){this._exrule.push(e)}},exdate:function(e){if(!(e instanceof Date)){throw new TypeError(String(e)+" is not Date instance")}if(!ne(this._exdate.map(Number),Number(e))){this._exdate.push(e);Z.sort(this._exdate)}},valueOf:function(){var t=[];if(this._rrule.length){this._rrule.forEach(function(e){t.push("RRULE:"+e)})}if(this._rdate.length){t.push("RDATE:"+this._rdate.map(function(e){return Z.timeToUntilString(e)}).join(","))}if(this._exrule.length){this._exrule.forEach(function(e){t.push("EXRULE:"+e)})}if(this._exdate.length){t.push("EXDATE:"+this._exdate.map(function(e){return Z.timeToUntilString(e)}).join(","))}return t},toString:function(){return JSON.stringify(this.valueOf())},_iter:function(t){var r={};var e=this._exrule;var n=t.accept;function a(t,n){e.forEach(function(e){e.between(t,n,true).forEach(function(e){r[Number(e)]=true})})}this._exdate.forEach(function(e){r[Number(e)]=true});t.accept=function(e){var t=Number(e);if(!r[t]){a(new Date(t-1),new Date(t+1));if(!r[t]){r[t]=true;return n.call(this,e)}}return true};if(t.method==="between"){a(t.args.after,t.args.before);t.accept=function(e){var t=Number(e);if(!r[t]){r[t]=true;return n.call(this,e)}return true}}for(var i=0;i-1){a=f.split("(");l=a[0];o=parseInt(a.slice(1,-1),10)}else{for(s=0;s0&&r[0]===" "){a[n-1]+=r.slice(1);a.splice(n,1)}else{n+=1}}}else{a=e.split(/\s/)}var i=[];var s=[];var o=[];var l=[];var f,h,u,c,y,d,p,w,v,m,b;if(!t.forceset&&a.length===1&&(e.indexOf(":")===-1||e.indexOf("RRULE:")===0)){return this._parseRfcRRule(a[0],{cache:t.cache,dtstart:t.dtstart,ignoretz:t.ignoretz,tzinfos:t.tzinfos})}else{for(n=0;n1||s.length||o.length||l.length){p=new _(!t.cache);for(w=0;w