rrule.min.js 28 KB

1
  1. (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(e<Z.ORDINAL_BASE){throw new Error("dates lower than "+Z.ORDINAL_BASE+" are not supported")}return Z.daysBetween(e,Z.ORDINAL_BASE)},fromOrdinal:function(e){var t=e*Z.ONE_DAY;return new Date(Z.ORDINAL_BASE.getTime()-Z.tzOffset(Z.ORDINAL_BASE)+t+Z.tzOffset(new Date(t)))},monthRange:function(e,t){var n=new Date(e,t,1);return[Z.getWeekday(n),Z.getMonthDays(n)]},getMonthDays:function(e){var t=e.getMonth();return t===1&&Z.isLeapYear(e.getFullYear())?29:Z.MONTH_DAYS[t]},getWeekday:function(e){return Z.PY_WEEKDAYS[e.getDay()]},combine:function(e,t){t=t||e;return new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds())},clone:function(e){var t=new Date(e.getTime());return t},cloneDates:function(e){var t=[];for(var n=0;n<e.length;n++){t.push(Z.clone(e[n]))}return t},sort:function(e){e.sort(function(e,t){return e.getTime()-t.getTime()})},timeToUntilString:function(e){var t;var n=new Date(e);var r=[n.getUTCFullYear(),n.getUTCMonth()+1,n.getUTCDate(),"T",n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),"Z"];for(var a=0;a<r.length;a++){t=r[a];if(!/[TZ]/.test(t)&&t<10)r[a]="0"+String(t)}return r.join("")},untilStringToDate:function(e){var t=/^(\d{4})(\d{2})(\d{2})(T(\d{2})(\d{2})(\d{2})Z?)?$/;var n=t.exec(e);if(!n)throw new Error("Invalid UNTIL value: "+e);return new Date(Date.UTC(n[1],n[2]-1,n[3],n[5]||0,n[6]||0,n[7]||0))}};Z.Time=function(e,t,n,r){this.hour=e;this.minute=t;this.second=n;this.millisecond=r||0};Z.Time.prototype={constructor:Z.Time,getHours:function(){return this.hour},getMinutes:function(){return this.minute},getSeconds:function(){return this.second},getMilliseconds:function(){return this.millisecond},getTime:function(){return(this.hour*60*60+this.minute*60+this.second)*1e3+this.millisecond}};var r=function(e,t){if(arguments.length===1){t=e;e=0}var n=[];for(var r=e;r<t;r++)n.push(r);return n};var k=function(e,t){var n=0;var r=[];if(e instanceof Array){for(;n<t;n++)r[n]=[].concat(e)}else{for(;n<t;n++)r[n]=e}return r};var g=function(e,t,n){var r=e.split(t);return n?r.slice(0,n).concat([r.slice(n).join(t)]):r};var J=function(e,t){var n=e%t;return n*t<0?n+t:n};var ee=function(e,t){return{div:Math.floor(e/t),mod:J(e,t)}};var te=function(e){return e instanceof Array&&e.length===0?false:Boolean(e)};var ne=function(e,t){return e.indexOf(t)!==-1};var T=[].concat(k(1,31),k(2,28),k(3,31),k(4,30),k(5,31),k(6,30),k(7,31),k(8,31),k(9,30),k(10,31),k(11,30),k(12,31),k(1,7));var Y=[].concat(k(1,31),k(2,29),k(3,31),k(4,30),k(5,31),k(6,30),k(7,31),k(8,31),k(9,30),k(10,31),k(11,30),k(12,31),k(1,7));var t=r(1,29);var n=r(1,30);var a=r(1,31);var i=r(1,32);var D=[].concat(i,n,i,a,i,a,i,i,a,i,a,i,i.slice(0,7));var R=[].concat(i,t,i,a,i,a,i,i,a,i,a,i,i.slice(0,7));t=r(-28,0);n=r(-29,0);a=r(-30,0);i=r(-31,0);var O=[].concat(i,n,i,a,i,a,i,i,a,i,a,i,i.slice(0,7));var A=[].concat(i,t,i,a,i,a,i,i,a,i,a,i,i.slice(0,7));var L=[0,31,60,91,121,152,182,213,244,274,305,335,366];var S=[0,31,59,90,120,151,181,212,243,273,304,334,365];var N=function(){for(var e=[],t=0;t<55;t++)e=e.concat(r(7));return e}();var s=["MO","TU","WE","TH","FR","SA","SU"];var b=function(e,t){if(t===0)throw new Error("Can't create weekday with n == 0");this.weekday=e;this.n=t};b.prototype={constructor:b,nth:function(e){return this.n===e?this:new b(this.weekday,e)},equals:function(e){return this.weekday===e.weekday&&this.n===e.n},toString:function(){var e=s[this.weekday];if(this.n)e=(this.n>0?"+":"")+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<i.bysetpos.length;o++){var l=i.bysetpos[o];if(l===0||!(l>=-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;o<i.bymonthday.length;o++){l=i.bymonthday[o];if(l>0){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;o<i.byweekday.length;o++){var y=i.byweekday[o];if(typeof y==="number"){u.push(y)}else if(!y.n||i.freq>re.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?[i.dtstart.getHours()]:null}else if(typeof i.byhour==="number"){i.byhour=[i.byhour]}if(i.byminute===null){i.byminute=i.freq<re.MINUTELY?[i.dtstart.getMinutes()]:null}else if(typeof i.byminute==="number"){i.byminute=[i.byminute]}if(i.bysecond===null){i.bysecond=i.freq<re.SECONDLY?[i.dtstart.getSeconds()]:null}else if(typeof i.bysecond==="number"){i.bysecond=[i.bysecond]}if(i.freq>=re.HOURLY){this.timeset=null}else{this.timeset=[];for(o=0;o<i.byhour.length;o++){var d=i.byhour[o];for(var p=0;p<i.byminute.length;p++){var w=i.byminute[p];for(var v=0;v<i.bysecond.length;v++){var m=i.bysecond[v];this.timeset.push(new Z.Time(d,w,m,s))}}}Z.sort(this.timeset)}};re.FREQUENCIES=["YEARLY","MONTHLY","WEEKLY","DAILY","HOURLY","MINUTELY","SECONDLY"];re.YEARLY=0;re.MONTHLY=1;re.WEEKLY=2;re.DAILY=3;re.HOURLY=4;re.MINUTELY=5;re.SECONDLY=6;re.MO=new b(0);re.TU=new b(1);re.WE=new b(2);re.TH=new b(3);re.FR=new b(4);re.SA=new b(5);re.SU=new b(6);re.DEFAULT_OPTIONS={freq:null,dtstart:null,interval:1,wkst:re.MO,count:null,until:null,bysetpos:null,bymonth:null,bymonthday:null,bynmonthday:null,byyearday:null,byweekno:null,byweekday:null,bynweekday:null,byhour:null,byminute:null,bysecond:null,byeaster:null};re.parseText=function(e,t){return c().parseText(e,t)};re.fromText=function(e,t){return c().fromText(e,t)};re.optionsToString=function(e){var t,n,r;var a=[];var i=Object.keys(e);var s=Object.keys(re.DEFAULT_OPTIONS);for(var o=0;o<i.length;o++){if(!ne(s,i[o]))continue;t=i[o].toUpperCase();n=e[i[o]];r=[];if(n===null||n instanceof Array&&!n.length)continue;switch(t){case"FREQ":n=re.FREQUENCIES[e.freq];break;case"WKST":if(!(n instanceof b)){n=new b(n)}break;case"BYWEEKDAY":t="BYDAY";if(!(n instanceof Array))n=[n];for(var l,f=0;f<n.length;f++){l=n[f];if(l instanceof b){}else if(l instanceof Array){l=new b(l[0],l[1])}else{l=new b(l)}r[f]=l.toString()}n=r;break;case"DTSTART":case"UNTIL":n=Z.timeToUntilString(n);break;default:if(n instanceof Array){for(f=0;f<n.length;f++)r[f]=String(n[f]);n=r}else{n=String(n)}}a.push([t,n])}var h=[];for(o=0;o<a.length;o++){var u=a[o];h.push(u[0]+"="+u[1].toString())}return h.join(";")};re.prototype={constructor:re,all:function(e){if(e){return this._iter(new o("all",{},e))}else{var t=this._cacheGet("all");if(t===false){t=this._iter(new l("all",{}));this._cacheAdd("all",t)}return t}},between:function(e,t,n,r){var a={before:t,after:e,inc:n};if(r){return this._iter(new o("between",a,r))}var i=this._cacheGet("between",a);if(i===false){i=this._iter(new l("between",a));this._cacheAdd("between",i,a)}return i},before:function(e,t){var n={dt:e,inc:t};var r=this._cacheGet("before",n);if(r===false){r=this._iter(new l("before",n));this._cacheAdd("before",r,n)}return r},after:function(e,t){var n={dt:e,inc:t};var r=this._cacheGet("after",n);if(r===false){r=this._iter(new l("after",n));this._cacheAdd("after",r,n)}return r},count:function(){return this.all().length},toString:function(){return re.optionsToString(this.origOptions)},toText:function(e,t){return c().toText(this,e,t)},isFullyConvertibleToText:function(){return c().isFullyConvertible(this)},_cacheAdd:function(e,t,n){if(!this._cache)return;if(t){t=t instanceof Date?Z.clone(t):Z.cloneDates(t)}if(e==="all"){this._cache.all=t}else{n._value=t;this._cache[e].push(n)}},_cacheGet:function(e,r){if(!this._cache)return false;var t=false;var a=r?Object.keys(r):[];var n=function(e){for(var t,n=0;n<a.length;n++){t=a[n];if(String(r[t])!==String(e[t]))return true}return false};if(e==="all"){t=this._cache.all}else{for(var i,s=0;s<this._cache[e].length;s++){i=this._cache[e][s];if(a.length&&n(i))continue;t=i._value;break}}if(!t&&this._cache.all){var o=new l(e,r);for(s=0;s<this._cache.all.length;s++){if(!o.accept(this._cache.all[s]))break}t=o.getValue();this._cacheAdd(e,t,r)}return t instanceof Array?Z.cloneDates(t):t instanceof Date?Z.clone(t):t},clone:function(){return new re(this.origOptions)},_iter:function(e){var t=this.options.dtstart;var n=this.options.dtstart%1e3;var r=t.getFullYear();var a=t.getMonth()+1;var i=t.getDate();var s=t.getHours();var o=t.getMinutes();var l=t.getSeconds();var f=Z.getWeekday(t);var h=this.options.freq;var u=this.options.interval;var c=this.options.wkst;var y=this.options.until;var d=this.options.bymonth;var p=this.options.byweekno;var w=this.options.byyearday;var v=this.options.byweekday;var m=this.options.byeaster;var b=this.options.bymonthday;var g=this.options.bynmonthday;var _=this.options.bysetpos;var E=this.options.byhour;var k=this.options.byminute;var T=this.options.bysecond;var Y=new ae(this);Y.rebuild(r,a);var D={};D[re.YEARLY]=Y.ydayset;D[re.MONTHLY]=Y.mdayset;D[re.WEEKLY]=Y.wdayset;D[re.DAILY]=Y.ddayset;D[re.HOURLY]=Y.ddayset;D[re.MINUTELY]=Y.ddayset;D[re.SECONDLY]=Y.ddayset;D=D[h];var R;if(h<re.HOURLY){R=this.timeset}else{var O={};O[re.HOURLY]=Y.htimeset;O[re.MINUTELY]=Y.mtimeset;O[re.SECONDLY]=Y.stimeset;O=O[h];if(h>=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<W;N++){S=B[N];q=te(d)&&!ne(d,Y.mmask[S])||te(p)&&!Y.wnomask[S]||te(v)&&!ne(v,Y.wdaymask[S])||te(Y.nwdaymask)&&!Y.nwdaymask[S]||m!==null&&!ne(Y.eastermask,S)||(te(b)||te(g))&&!ne(b,Y.mdaymask[S])&&!ne(g,Y.nmdaymask[S])||te(w)&&(S<Y.yearlen&&!ne(w,S+1)&&!ne(w,-Y.yearlen+S)||S>=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;U<W;U++){var P=B[U];if(P===null)continue;H.push(P)}if(j<0){S=H.slice(j)[0]}else{S=H[j]}var X=R[K];var G=Z.fromOrdinal(Y.yearordinal+S);var Q=Z.combine(G,X);if(!ne(V,Q))V.push(Q)}catch(e){}}Z.sort(V);for(N=0;N<V.length;N++){Q=V[N];if(y&&Q>y){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;N<W;N++){S=B[N];if(S!==null){G=Z.fromOrdinal(Y.yearordinal+S);for(U=0;U<R.length;U++){X=R[U];Q=Z.combine(G,X);if(y&&Q>y){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<s.length;t++){i=s[t].split("=");r=i[0];a=i[1];switch(r){case"FREQ":o.freq=re[a];break;case"WKST":o.wkst=re[a];break;case"COUNT":case"INTERVAL":case"BYSETPOS":case"BYMONTH":case"BYMONTHDAY":case"BYYEARDAY":case"BYWEEKNO":case"BYHOUR":case"BYMINUTE":case"BYSECOND":if(a.indexOf(",")!==-1){a=a.split(",");for(n=0;n<a.length;n++){if(/^[+-]?\d+$/.test(a[n]))a[n]=Number(a[n])}}else if(/^[+-]?\d+$/.test(a)){a=Number(a)}r=r.toLowerCase();o[r]=a;break;case"BYDAY":var l,f,h;var u=a.split(",");o.byweekday=[];for(n=0;n<u.length;n++){h=u[n];if(h.length===2){f=re[h];o.byweekday.push(f)}else{h=h.match(/^([+-]?\d)([A-Z]{2})$/);l=Number(h[1]);f=h[2];f=re[f].weekday;o.byweekday.push(new b(f,l))}}break;case"DTSTART":o.dtstart=Z.untilStringToDate(a);break;case"UNTIL":o.until=Z.untilStringToDate(a);break;case"BYEASTER":o.byeaster=Number(a);break;default:throw new Error("Unknown RRULE property '"+r+"'")}}return o};re.fromString=function(e){return new re(re.parseString(e))};var ae=function(e){this.rrule=e;this.lastyear=null;this.lastmonth=null;this.yearlen=null;this.nextyearlen=null;this.yearordinal=null;this.yearweekday=null;this.mmask=null;this.mrange=null;this.mdaymask=null;this.nmdaymask=null;this.wdaymask=null;this.wnomask=null;this.nwdaymask=null;this.eastermask=null};ae.prototype.easter=function(e,t){t=t||0;var n=e%19;var r=Math.floor(e/100);var a=e%100;var i=Math.floor(r/4);var s=r%4;var o=Math.floor((r+8)/25);var l=Math.floor((r-o+1)/3);var f=Math.floor(19*n+r-i-l+15)%30;var h=Math.floor(a/4);var u=a%4;var c=Math.floor(32+2*s+2*h-f-u)%7;var y=Math.floor((n+11*f+22*c)/451);var d=Math.floor((f+c-7*y+114)/31);var p=(f+c-7*y+114)%31+1;var w=Date.UTC(e,d-1,p+t);var v=Date.UTC(e,0,1);return[Math.ceil((w-v)/(1e3*60*60*24))]};ae.prototype.rebuild=function(e,t){var n=this.rrule;if(e!==this.lastyear){this.yearlen=Z.isLeapYear(e)?366:365;this.nextyearlen=Z.isLeapYear(e+1)?366:365;var r=new Date(e,0,1);this.yearordinal=Z.toOrdinal(r);this.yearweekday=Z.getWeekday(r);var a=Z.getWeekday(new Date(e,0,1));if(this.yearlen===365){this.mmask=[].concat(T);this.mdaymask=[].concat(R);this.nmdaymask=[].concat(A);this.wdaymask=N.slice(a);this.mrange=[].concat(S)}else{this.mmask=[].concat(Y);this.mdaymask=[].concat(D);this.nmdaymask=[].concat(O);this.wdaymask=N.slice(a);this.mrange=[].concat(L)}if(!te(n.options.byweekno)){this.wnomask=null}else{this.wnomask=k(0,this.yearlen+7);var i,s,o;i=s=J(7-this.yearweekday+n.options.wkst,7);if(i>=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;y<n.options.byweekno.length;y++){u=n.options.byweekno[y];if(u<0){u+=h+1}if(!(u>0&&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<this.yearlen){for(y=0;y<7;y++){this.wnomask[c]=1;c+=1;if(this.wdaymask[c]===n.options.wkst)break}}}if(i){var p;if(!ne(n.options.byweekno,-1)){var w=Z.getWeekday(new Date(e-1,0,1));var v=J(7-w+n.options.wkst,7);var m=Z.isLeapYear(e-1)?366:365;if(v>=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;c<i;c++)this.wnomask[c]=1}}}}if(te(n.options.bynweekday)&&(t!==this.lastmonth||e!==this.lastyear)){var b=[];if(n.options.freq===re.YEARLY){if(te(n.options.bymonth)){for(y=0;y<n.options.bymonth.length;y++){t=n.options.bymonth[y];b.push(this.mrange.slice(t-1,t+1))}}else{b=[[0,this.yearlen]]}}else if(n.options.freq===re.MONTHLY){b=[this.mrange.slice(t-1,t+1)]}if(te(b)){this.nwdaymask=k(0,this.yearlen);for(y=0;y<b.length;y++){var g=b[y];var _=g[0];var E=g[1];E-=1;for(d=0;d<n.options.bynweekday.length;d++){a=n.options.bynweekday[d][0];u=n.options.bynweekday[d][1];if(u<0){c=E+(u+1)*7;c-=J(this.wdaymask[c]-a,7)}else{c=_+(u-1)*7;c+=J(7-this.wdaymask[c]+a,7)}if(_<=c&&c<=E)this.nwdaymask[c]=1}}}this.lastyear=e;this.lastmonth=t}if(n.options.byeaster!==null){this.eastermask=this.easter(e,n.options.byeaster)}};ae.prototype.ydayset=function(e,t,n){return[r(this.yearlen),0,this.yearlen]};ae.prototype.mdayset=function(e,t,n){var r=k(null,this.yearlen);var a=this.mrange[t-1];var i=this.mrange[t];for(var s=a;s<i;s++)r[s]=s;return[r,a,i]};ae.prototype.wdayset=function(e,t,n){var r=k(null,this.yearlen+7);var a=Z.toOrdinal(new Date(e,t-1,n))-this.yearordinal;var i=a;for(var s=0;s<7;s++){r[a]=a;++a;if(this.wdaymask[a]===this.rrule.options.wkst)break}return[r,i,a]};ae.prototype.ddayset=function(e,t,n){var r=k(null,this.yearlen);var a=Z.toOrdinal(new Date(e,t-1,n))-this.yearordinal;r[a]=a;return[r,a,a+1]};ae.prototype.htimeset=function(e,t,n,r){var a=[];var i=this.rrule;for(var s=0;s<i.options.byminute.length;s++){t=i.options.byminute[s];for(var o=0;o<i.options.bysecond.length;o++){n=i.options.bysecond[o];a.push(new Z.Time(e,t,n,r))}}Z.sort(a);return a};ae.prototype.mtimeset=function(e,t,n,r){var a=[];var i=this.rrule;for(var s=0;s<i.options.bysecond.length;s++){n=i.options.bysecond[s];a.push(new Z.Time(e,t,n,r))}Z.sort(a);return a};ae.prototype.stimeset=function(e,t,n,r){return[new Z.Time(e,t,n,r)]};var l=function(e,t){this.init(e,t)};l.prototype={constructor:l,init:function(e,t){this.method=e;this.args=t;this.minDate=null;this.maxDate=null;this._result=[];if(e==="between"){this.maxDate=t.inc?t.before:new Date(t.before.getTime()-1);this.minDate=t.inc?t.after:new Date(t.after.getTime()+1)}else if(e==="before"){this.maxDate=t.inc?t.dt:new Date(t.dt.getTime()-1)}else if(e==="after"){this.minDate=t.inc?t.dt:new Date(t.dt.getTime()+1)}},accept:function(e){var t=this.minDate&&e<this.minDate;var n=this.maxDate&&e>this.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<this._rdate.length;i++){if(!t.accept(new Date(this._rdate[i])))break}this._rrule.forEach(function(e){e._iter(t)});var s=t._result;Z.sort(s);switch(t.method){case"all":case"between":return s;case"before":return s.length&&s[s.length-1]||null;case"after":return s.length&&s[0]||null;default:return null}},clone:function(){var e=new _(!!this._cache);var t;for(t=0;t<this._rrule.length;t++){e.rrule(this._rrule[t].clone())}for(t=0;t<this._rdate.length;t++){e.rdate(new Date(this._rdate[t]))}for(t=0;t<this._exrule.length;t++){e.exrule(this._exrule[t].clone())}for(t=0;t<this._exdate.length;t++){e.exdate(new Date(this._exdate[t]))}return e}};var f=["all","between","before","after","count","_cacheAdd","_cacheGet"];f.forEach(function(e){_.prototype[e]=re.prototype[e]});var y=function(){};y.DEFAULT_OPTIONS={dtstart:null,cache:false,unfold:false,forceset:false,compatible:false,ignoretz:false,tzinfos:null};y._freq_map={YEARLY:re.YEARLY,MONTHLY:re.MONTHLY,WEEKLY:re.WEEKLY,DAILY:re.DAILY,HOURLY:re.HOURLY,MINUTELY:re.MINUTELY,SECONDLY:re.SECONDLY};y._weekday_map={MO:0,TU:1,WE:2,TH:3,FR:4,SA:5,SU:6};y.prototype={constructor:y,_handle_int:function(e,t,n,r){e[t.toLowerCase()]=parseInt(n,10)},_handle_int_list:function(e,t,n,r){e[t.toLowerCase()]=n.split(",").map(function(e){return parseInt(e,10)})},_handle_FREQ:function(e,t,n,r){e["freq"]=y._freq_map[n]},_handle_UNTIL:function(e,t,n,r){try{e["until"]=Z.untilStringToDate(n)}catch(e){throw new Error("invalid until date")}},_handle_WKST:function(e,t,n,r){e["wkst"]=y._weekday_map[n]},_handle_BYWEEKDAY:function(e,t,n,r){var a,i,s,o,l,f;var h=[];var u=n.split(",");for(i=0;i<u.length;i++){f=u[i];if(f.indexOf("(")>-1){a=f.split("(");l=a[0];o=parseInt(a.slice(1,-1),10)}else{for(s=0;s<f.length;s++){if("+-0123456789".indexOf(f[s])===-1)break}o=f.slice(0,s)||null;l=f.slice(s);if(o)o=parseInt(o,10)}var c=new b(y._weekday_map[l],o);h.push(c)}e["byweekday"]=h},_parseRfcRRule:function(e,t){t=t||{};t.dtstart=t.dtstart||null;t.cache=t.cache||false;t.ignoretz=t.ignoretz||false;t.tzinfos=t.tzinfos||null;var n,r,a;if(e.indexOf(":")!==-1){a=e.split(":");n=a[0];r=a[1];if(n!=="RRULE")throw new Error("unknown parameter name")}else{r=e}var i;var s={};var o=r.split(";");for(i=0;i<o.length;i++){a=o[i].split("=");n=a[0].toUpperCase();r=a[1].toUpperCase();try{this["_handle_"+n](s,n,r,{ignoretz:t.ignoretz,tzinfos:t.tzinfos})}catch(e){throw new Error("unknown parameter '"+n+"':"+r)}}s.dtstart=s.dtstart||t.dtstart;return new re(s,!t.cache)},_parseRfc:function(e,t){if(t.compatible){t.forceset=true;t.unfold=true}e=e&&e.toUpperCase().trim();if(!e)throw new Error("Invalid empty string");var n=0;var r,a;if(t.unfold){a=e.split("\n");while(n<a.length){r=a[n]=a[n].replace(/\s+$/g,"");if(!r){a.splice(n,1)}else if(n>0&&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;n<a.length;n++){r=a[n];if(!r)continue;if(r.indexOf(":")===-1){f="RRULE";h=r}else{u=g(r,":",1);f=u[0];h=u[1]}c=f.split(";");if(!c)throw new Error("empty property name");f=c[0];c=c.slice(1);if(f==="RRULE"){for(w=0;w<c.length;w++){y=c[w];throw new Error("unsupported RRULE parm: "+y)}i.push(h)}else if(f==="RDATE"){for(w=0;w<c.length;w++){y=c[w];if(y!=="VALUE=DATE-TIME"&&y!=="VALUE=DATE"){throw new Error("unsupported RDATE parm: "+y)}}s.push(h)}else if(f==="EXRULE"){for(w=0;w<c.length;w++){y=c[w];throw new Error("unsupported EXRULE parm: "+y)}o.push(h)}else if(f==="EXDATE"){for(w=0;w<c.length;w++){y=c[w];if(y!=="VALUE=DATE-TIME"&&y!=="VALUE=DATE"){throw new Error("unsupported RDATE parm: "+y)}}l.push(h)}else if(f==="DTSTART"){d=Z.untilStringToDate(h)}else{throw new Error("unsupported property: "+f)}}if(t.forceset||i.length>1||s.length||o.length||l.length){p=new _(!t.cache);for(w=0;w<i.length;w++){p.rrule(this._parseRfcRRule(i[w],{dtstart:t.dtstart||d,ignoretz:t.ignoretz,tzinfos:t.tzinfos}))}for(w=0;w<s.length;w++){m=s[w].split(",");for(v=0;v<m.length;v++){b=m[v];p.rdate(Z.untilStringToDate(b))}}for(w=0;w<o.length;w++){p.exrule(this._parseRfcRRule(o[w],{dtstart:t.dtstart||d,ignoretz:t.ignoretz,tzinfos:t.tzinfos}))}for(w=0;w<l.length;w++){m=l[w].split(",");for(v=0;v<m.length;v++){b=m[v];p.exdate(Z.untilStringToDate(b))}}if(t.campatiable&&t.dtstart)p.rdate(d);return p}else{return this._parseRfcRRule(i[0],{dtstart:t.dtstart||d,cache:t.cache,ignoretz:t.ignoretz,tzinfos:t.tzinfos})}}},parse:function(e,t){t=t||{};var n=[];var r=Object.keys(t);var a=Object.keys(y.DEFAULT_OPTIONS);r.forEach(function(e){if(!ne(a,e))n.push(e)},this);if(n.length)throw new Error("Invalid options: "+n.join(", "));a.forEach(function(e){if(!ne(r,e))t[e]=y.DEFAULT_OPTIONS[e]});return this._parseRfc(e,t)}};y.prototype._handle_DTSTART=function(e,t,n,r){e[t.toLowerCase()]=Z.untilStringToDate(n)};y.prototype._handle_BYDAY=y.prototype._handle_BYWEEKDAY;y.prototype._handle_INTERVAL=y.prototype._handle_int;y.prototype._handle_COUNT=y.prototype._handle_int;["_handle_BYSETPOS","_handle_BYMONTH","_handle_BYMONTHDAY","_handle_BYYEARDAY","_handle_BYEASTER","_handle_BYWEEKNO","_handle_BYHOUR","_handle_BYMINUTE","_handle_BYSECOND"].forEach(function(e){y.prototype[e]=y.prototype._handle_int_list});var h=new y;var u=function(){return h.parse.apply(h,arguments)};re.RRule=re;re.RRuleSet=_;re.rrulestr=u;return re;function c(){if(!c._nlp){if(e&&e._getRRuleNLP){c._nlp=e._getRRuleNLP(re)}else if(typeof require==="function"){c._nlp=require("./nlp")(re)}else{throw new Error("You need to include rrule/nlp.js for fromText/toText to work.")}}return c._nlp}});