forked from bunkat/later
-
Notifications
You must be signed in to change notification settings - Fork 0
/
later.min.js
1 lines (1 loc) · 22.6 KB
/
later.min.js
1
(function(){"use strict";var CronParser=function(){var NAMES={JAN:1,FEB:2,MAR:3,APR:4,MAY:5,JUN:6,JUL:7,AUG:8,SEP:9,OCT:10,NOV:11,DEC:12,SUN:1,MON:2,TUE:3,WED:4,THU:5,FRI:6,SAT:7};var FIELDS={s:[0,0,59],m:[1,0,59],h:[2,0,23],D:[3,1,31],M:[4,1,12],Y:[6,1970,2099],d:[5,1,7,1]};var getValue=function(value,offset){return isNaN(value)?NAMES[value]:+value+(offset||0)};var cloneSchedule=function(sched){var clone={},field;for(field in sched){if(field!=="dc"&&field!=="d"){clone[field]=sched[field].slice(0)}}return clone};var add=function(sched,name,min,max,inc){var i=min;if(!sched[name]){sched[name]=[]}while(i<=max){if(sched[name].indexOf(i)<0){sched[name].push(i)}i+=inc||1}};var addHash=function(schedules,curSched,value,hash){if(curSched.d&&!curSched.dc||curSched.dc&&curSched.dc.indexOf(hash)<0){schedules.push(cloneSchedule(curSched));curSched=schedules[schedules.length-1]}add(curSched,"d",value,value);add(curSched,"dc",hash,hash)};var addWeekday=function(s,curSched,value){var except1={},except2={};if(value===1){add(curSched,"D",1,3);add(curSched,"d",NAMES.MON,NAMES.FRI);add(except1,"D",2,2);add(except1,"d",NAMES.TUE,NAMES.FRI);add(except2,"D",3,3);add(except2,"d",NAMES.TUE,NAMES.FRI)}else{add(curSched,"D",value-1,value+1);add(curSched,"d",NAMES.MON,NAMES.FRI);add(except1,"D",value-1,value-1);add(except1,"d",NAMES.MON,NAMES.THU);add(except2,"D",value+1,value+1);add(except2,"d",NAMES.TUE,NAMES.FRI)}s.exceptions.push(except1);s.exceptions.push(except2)};var addRange=function(item,curSched,name,min,max,offset){var incSplit=item.split("/"),inc=+incSplit[1],range=incSplit[0];if(range!=="*"&&range!=="0"){var rangeSplit=range.split("-");min=getValue(rangeSplit[0],offset);max=getValue(rangeSplit[1],offset)}add(curSched,name,min,max,inc)};var parse=function(item,s,name,min,max,offset){var value,split,schedules=s.schedules,curSched=schedules[schedules.length-1];if(item==="L"){item=min-1}if((value=getValue(item,offset))!=null){add(curSched,name,value,value)}else if((value=getValue(item.replace("W",""),offset))!=null){addWeekday(s,curSched,value)}else if((value=getValue(item.replace("L",""),offset))!=null){addHash(schedules,curSched,value,min-1)}else if((split=item.split("#")).length===2){value=getValue(split[0],offset);addHash(schedules,curSched,value,getValue(split[1]))}else{addRange(item,curSched,name,min,max,offset)}};var isHash=function(item){return item.indexOf("#")>-1||item.indexOf("L")>0};var itemSorter=function(a,b){return isHash(a)&&!isHash(b)?1:0};var parseExpr=function(expr){var schedule={schedules:[{}],exceptions:[]},components=expr.split(" "),field,f,component,items;for(field in FIELDS){f=FIELDS[field];component=components[f[0]];if(component&&component!=="*"&&component!=="?"){items=component.split(",").sort(itemSorter);var i,length=items.length;for(i=0;i<length;i++){parse(items[i],schedule,field,f[1],f[2],f[3])}}}return schedule};return{parse:function(expr,hasSeconds){var e=expr.toUpperCase();return parseExpr(hasSeconds?e:"0 "+e)}}};var root=typeof exports!=="undefined"&&exports!==null?exports:window;root.cronParser=CronParser}).call(this);var root=typeof exports!=="undefined"&&exports!==null?exports:window;var recur=root.recur;if(!recur&&typeof require!=="undefined"){recur=require("./recur").recur}(function(){"use strict";var EnParser=function(){var pos=0,input="",error;var TOKENTYPES={eof:/^$/,rank:/^((\d\d\d\d)|([2-5]?1(st)?|[2-5]?2(nd)?|[2-5]?3(rd)?|(0|[1-5]?[4-9]|[1-5]0|1[1-3])(th)?))\b/,time:/^((([0]?[1-9]|1[0-2]):[0-5]\d(\s)?(am|pm))|(([0]?\d|1\d|2[0-3]):[0-5]\d))\b/,dayName:/^((sun|mon|tue(s)?|wed(nes)?|thu(r(s)?)?|fri|sat(ur)?)(day)?)\b/,monthName:/^(jan(uary)?|feb(ruary)?|ma((r(ch)?)?|y)|apr(il)?|ju(ly|ne)|aug(ust)?|oct(ober)?|(sept|nov|dec)(ember)?)\b/,yearIndex:/^(\d\d\d\d)\b/,every:/^every\b/,after:/^after\b/,second:/^(s|sec(ond)?(s)?)\b/,minute:/^(m|min(ute)?(s)?)\b/,hour:/^(h|hour(s)?)\b/,day:/^(day(s)?( of the month)?)\b/,dayInstance:/^day instance\b/,dayOfWeek:/^day(s)? of the week\b/,dayOfYear:/^day(s)? of the year\b/,weekOfYear:/^week(s)?( of the year)?\b/,weekOfMonth:/^week(s)? of the month\b/,weekday:/^weekday\b/,weekend:/^weekend\b/,month:/^month(s)?\b/,year:/^year(s)?\b/,between:/^between (the)?\b/,start:/^(start(ing)? (at|on( the)?)?)\b/,at:/^(at|@)\b/,and:/^(,|and\b)/,except:/^(except\b)/,also:/(also)\b/,first:/^(first)\b/,last:/^last\b/,"in":/^in\b/,of:/^of\b/,onthe:/^on the\b/,on:/^on\b/,through:/(-|^(to|through)\b)/};var NAMES={jan:1,feb:2,mar:3,apr:4,may:5,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12,sun:1,mon:2,tue:3,wed:4,thu:5,fri:6,sat:7,"1st":1,fir:1,"2nd":2,sec:2,"3rd":3,thi:3,"4th":4,"for":4};var t=function(start,end,text,type){return{startPos:start,endPos:end,text:text,type:type}};var peek=function(expected){var scanTokens=expected instanceof Array?expected:[expected],whiteSpace=/\s+/,token,curInput,m,scanToken,start,len;scanTokens.push(whiteSpace);start=pos;while(!token||token.type===whiteSpace){len=-1;curInput=input.substring(start);token=t(start,start,input.split(whiteSpace)[0]);var i,length=scanTokens.length;for(i=0;i<length;i++){scanToken=scanTokens[i];m=scanToken.exec(curInput);if(m&&m.index===0&&m[0].length>len){len=m[0].length;token=t(start,start+len,curInput.substring(0,len),scanToken)}}if(token.type===whiteSpace){start=token.endPos}}return token};var scan=function(expectedToken){var token=peek(expectedToken);pos=token.endPos;return token};var parseThroughExpr=function(tokenType){var start=+parseTokenValue(tokenType),end=checkAndParse(TOKENTYPES.through)?+parseTokenValue(tokenType):start,nums=[];for(var i=start;i<=end;i++){nums.push(i)}return nums};var parseRanges=function(tokenType){var nums=parseThroughExpr(tokenType);while(checkAndParse(TOKENTYPES.and)){nums=nums.concat(parseThroughExpr(tokenType))}return nums};var parseEvery=function(r){var num,period,start,end;if(checkAndParse(TOKENTYPES.weekend)){r.on(NAMES.sun,NAMES.sat).dayOfWeek()}else if(checkAndParse(TOKENTYPES.weekday)){r.on(NAMES.mon,NAMES.tue,NAMES.wed,NAMES.thu,NAMES.fri).dayOfWeek()}else{num=parseTokenValue(TOKENTYPES.rank);r.every(num);period=parseTimePeriod(r);if(checkAndParse(TOKENTYPES.start)){num=parseTokenValue(TOKENTYPES.rank);r.startingOn(num);parseToken(period.type)}else if(checkAndParse(TOKENTYPES.between)){start=parseTokenValue(TOKENTYPES.rank);if(checkAndParse(TOKENTYPES.and)){end=parseTokenValue(TOKENTYPES.rank);r.between(start,end)}}}};var parseOnThe=function(r){if(checkAndParse(TOKENTYPES.first)){r.first()}else if(checkAndParse(TOKENTYPES.last)){r.last()}else{r.on(parseRanges(TOKENTYPES.rank))}parseTimePeriod(r)};var parseScheduleExpr=function(str){pos=0;input=str;error=-1;var r=recur();while(pos<input.length&&error<0){var token=parseToken([TOKENTYPES.every,TOKENTYPES.after,TOKENTYPES.onthe,TOKENTYPES.on,TOKENTYPES.of,TOKENTYPES["in"],TOKENTYPES.at,TOKENTYPES.and,TOKENTYPES.except,TOKENTYPES.also]);switch(token.type){case TOKENTYPES.every:parseEvery(r);break;case TOKENTYPES.after:r.after(parseTokenValue(TOKENTYPES.rank));parseTimePeriod(r);break;case TOKENTYPES.onthe:parseOnThe(r);break;case TOKENTYPES.on:r.on(parseRanges(TOKENTYPES.dayName)).dayOfWeek();break;case TOKENTYPES.of:r.on(parseRanges(TOKENTYPES.monthName)).month();break;case TOKENTYPES["in"]:r.on(parseRanges(TOKENTYPES.yearIndex)).year();break;case TOKENTYPES.at:r.at(parseTokenValue(TOKENTYPES.time));while(checkAndParse(TOKENTYPES.and)){r.at(parseTokenValue(TOKENTYPES.time))}break;case TOKENTYPES.also:r.and();break;case TOKENTYPES.except:r.except();break;default:error=pos}}return{schedules:r.schedules,exceptions:r.exceptions,error:error}};var parseTimePeriod=function(r){var timePeriod=parseToken([TOKENTYPES.second,TOKENTYPES.minute,TOKENTYPES.hour,TOKENTYPES.dayOfYear,TOKENTYPES.dayOfWeek,TOKENTYPES.dayInstance,TOKENTYPES.day,TOKENTYPES.month,TOKENTYPES.year,TOKENTYPES.weekOfMonth,TOKENTYPES.weekOfYear]);switch(timePeriod.type){case TOKENTYPES.second:r.second();break;case TOKENTYPES.minute:r.minute();break;case TOKENTYPES.hour:r.hour();break;case TOKENTYPES.dayOfYear:r.dayOfYear();break;case TOKENTYPES.dayOfWeek:r.dayOfWeek();break;case TOKENTYPES.dayInstance:r.dayOfWeekCount();break;case TOKENTYPES.day:r.dayOfMonth();break;case TOKENTYPES.weekOfMonth:r.weekOfMonth();break;case TOKENTYPES.weekOfYear:r.weekOfYear();break;case TOKENTYPES.month:r.month();break;case TOKENTYPES.year:r.year();break;default:error=pos}return timePeriod};var checkAndParse=function(tokenType){var found=peek(tokenType).type===tokenType;if(found){scan(tokenType)}return found};var parseToken=function(tokenType){var t=scan(tokenType);if(t.type){t.text=convertString(t.text,tokenType)}else{error=pos}return t};var parseTokenValue=function(tokenType){return parseToken(tokenType).text};var convertString=function(str,tokenType){var output=str;switch(tokenType){case TOKENTYPES.time:var parts=str.split(/(:|am|pm)/),hour=parts[3]==="pm"?parseInt(parts[0],10)+12:parts[0],min=parts[2].trim();output=(hour.length===1?"0":"")+hour+":"+min;break;case TOKENTYPES.rank:output=parseInt(/^\d+/.exec(str)[0],10);break;case TOKENTYPES.monthName:case TOKENTYPES.dayName:output=NAMES[str.substring(0,3)];break}return output};return{parse:function(str){return parseScheduleExpr(str.toLowerCase())}}};root.enParser=EnParser}).call(this);(function(){"use strict";var Later=function(resolution,useLocalTime){var isLocal=useLocalTime||false,get="get"+(isLocal?"":"UTC"),exec=true,SEC=1e3,MIN=SEC*60,HOUR=MIN*60,DAY=HOUR*24,ceil=Math.ceil,floor=Math.floor,max=Math.max,dateProto=Date.prototype,getYear=dateProto[get+"FullYear"],getMonth=dateProto[get+"Month"],getDate=dateProto[get+"Date"],getDay=dateProto[get+"Day"],getHour=dateProto[get+"Hours"],getMin=dateProto[get+"Minutes"],getSec=dateProto[get+"Seconds"];resolution=resolution===undefined?1:resolution;var nextInRange=function(val,values,minOffset){var cur,next=null,min=values[0],i=values.length;while(i--){cur=values[i];if(cur===val){return val}min=cur<min?cur:min;next=cur>val&&(!next||cur<next)?cur:next}return next||(minOffset===undefined?min:min+minOffset)};var prevInRange=function(val,values,maxOffset){var cur,prev=null,i=values.length,max=values[i-1];while(i--){cur=values[i];if(cur===val){return val}max=cur>max?cur:max;prev=cur<val&&(!prev||cur>prev)?cur:prev}return prev!==null?prev:maxOffset===undefined?max:max-maxOffset};var nextDate=function(yr,mt,dt,hr,mn,sc){mt=mt===undefined?0:mt;dt=dt===undefined?1:dt;hr=hr===undefined?0:hr;mn=mn===undefined?0:mn;sc=sc===undefined?0:sc;return isLocal?new Date(yr,mt,dt,hr,mn,sc):new Date(Date.UTC(yr,mt,dt,hr,mn,sc))};var prevDate=function(yr,mt,dt,hr,mn,sc){mt=mt===undefined?11:mt;dt=dt===undefined?getDate.call(nextDate(yr,mt+1,0)):dt;hr=hr===undefined?23:hr;mn=mn===undefined?59:mn;sc=sc===undefined?59:sc;return isLocal?new Date(yr,mt,dt,hr,mn,sc):new Date(Date.UTC(yr,mt,dt,hr,mn,sc))};var pad=function(val){return(val<10?"0":"")+val};var getNextInvalidSchedule=function(sched,start,reverse){var Y,M,D,d,h,m,s,oJan1,oMonthStart,oWeekStart,oWeekStartY,oMonthEnd,oDec31,t,dy,wy,wm,dc,daysInYear,daysInMonth,firstDayOfMonth,weekStart,weeksInYear,weeksInMonth,x;var range=reverse?prevInRange:nextInRange,date=reverse?prevDate:nextDate;Y=getYear.call(start);M=getMonth.call(start);D=getDate.call(start);h=getHour.call(start);m=getMin.call(start);s=getSec.call(start);t=pad(h)+":"+pad(m)+":"+pad(s);if(sched.t&&range(t,sched.t)===t){return reverse?date(Y,M,D,h,m,s-1):date(Y,M,D,h,m,s+1)}if(sched.s&&range(s,sched.s,60)===s){return reverse?date(Y,M,D,h,m,s-1):date(Y,M,D,h,m,s+1)}if(sched.m&&range(m,sched.m,60)===m){return reverse?date(Y,M,D,h,m-1):date(Y,M,D,h,m+1)}if(sched.h&&range(h,sched.h,24)===h){return reverse?date(Y,M,D,h-1):date(Y,M,D,h+1)}if(sched.tb){if(t<sched.tb[0]){x=sched.tb[0].split(":");if(reverse){return date(Y,M,D-1,x[0],x[1],x[2]-1)}else{return date(Y,M,D,x[0],x[1],x[2])}}}if(sched.ta){if(t>=sched.ta[0]){if(reverse){x=sched.ta[0].split(":");return date(Y,M,D,x[0],x[1],x[2]-1)}else{return date(Y,M,D+1)}}}if(sched.dc){dc=floor((D-1)/7)+1;if(range(dc,sched.dc,0)===dc){return reverse?date(Y,M,D-1):date(Y,M,D+1)}}d=getDay.call(start);if(sched.d&&range(d+1,sched.d,7)===d+1){return reverse?date(Y,M,D-1):date(Y,M,D+1)}if(sched.wm){firstDayOfMonth=getDay.call(nextDate(Y,M,1));wm=floor((D+firstDayOfMonth-1)/7+1);weeksInMonth=floor((daysInMonth+firstDayOfMonth-1)/7+1);if((range(wm,sched.wm,weeksInMonth)||weeksInMonth)===wm){return reverse?date(Y,M,D-1):date(Y,M,D+1)}}oMonthEnd=nextDate(Y,M+1,0);daysInMonth=getDate.call(oMonthEnd);if(sched.D&&(range(D,sched.D,daysInMonth)||daysInMonth)===D){return reverse?date(Y,M,D-1):date(Y,M,D+1)}oJan1=nextDate(Y,0,1,12);oDec31=nextDate(Y+1,0,0,12);if(sched.wy){oWeekStart=date(Y,M,D+4-(d||7));oWeekStartY=date(getYear.call(oWeekStart),0,1);weeksInYear=getDay.call(oJan1)===4||getDay.call(oDec31)===4?53:52;wy=ceil(((oWeekStart.getTime()-oWeekStartY.getTime())/DAY+1)/7);if((range(wy,sched.wy,weeksInYear)||weeksInYear)===wy){return reverse?date(Y,M,D-1):date(Y,M,D+1)}}if(sched.M&&range(M+1,sched.M,12)===M+1){return reverse?date(Y,M-1):date(Y,M+1)}if(sched.dy){dy=ceil((start.getTime()-oJan1.getTime())/DAY)+1;daysInYear=ceil((oDec31.getTime()-oJan1.getTime())/DAY)+1;if((range(dy,sched.dy,daysInYear)||daysInYear)===dy){return reverse?date(Y,M-1):date(Y,M+1)}}if(sched.Y&&range(Y,sched.Y,0)===Y){return reverse?date(Y-1):date(Y+1)}return start};var getNextForSchedule=function(sched,start,end,reverse){var next,inc,x,cur,Y,M,D,d,h,m,s,oJan1,oMonthStart,oWeekStart,oWeekStartY,oMonthEnd,oDec31,t,dy,wy,wm,dc,daysInYear,daysInMonth,firstDayOfMonth,weekStart,weeksInYear,weeksInMonth,maxLoopCount=1e3;var range=reverse?prevInRange:nextInRange,date=reverse?prevDate:nextDate;next=reverse?start:after(start,sched);while(next&&maxLoopCount--){if(end&&(!reverse&&next.getTime()>end.getTime()||reverse&&next.getTime()<end.getTime())){return null}Y=getYear.call(next);M=getMonth.call(next);D=getDate.call(next);if(sched.Y&&(inc=range(Y,sched.Y,0))!==Y){next=!reverse&&inc>Y||reverse&&inc<Y?date(inc):null;continue}oJan1=nextDate(Y,0,1,12,0,0);var cDate=nextDate(Y,M,D,12,0,0);oDec31=nextDate(Y+1,0,0);if(sched.dy){dy=ceil((cDate.getTime()-oJan1.getTime())/DAY)+1;daysInYear=ceil((oDec31.getTime()-oJan1.getTime())/DAY)+1;if(((inc=range(dy,sched.dy,daysInYear))||daysInYear)!==dy){next=date(Y,0,inc);continue}}if(sched.M&&(inc=range(M+1,sched.M,12))!==M+1){next=date(Y,inc-1);continue}d=getDay.call(next);if(sched.wy){oWeekStart=date(Y,M,D+4-(d||7),12);oWeekStartY=date(getYear.call(oWeekStart),0,1,12);weeksInYear=getDay.call(oJan1)===4||getDay.call(oDec31)===4?53:52;wy=ceil(((oWeekStart.getTime()-oWeekStartY.getTime())/DAY+1)/7);if(((inc=range(wy,sched.wy,weeksInYear))||weeksInYear)!==wy){if(inc<0)inc+=1;next=date(getYear.call(oWeekStart),getMonth.call(oWeekStart),getDate.call(oWeekStart)-3+(inc-wy)*7+(reverse?6:0));continue}}oMonthEnd=nextDate(Y,M+1,0,12);daysInMonth=getDate.call(oMonthEnd);if(sched.D&&((inc=range(D,sched.D,daysInMonth))||daysInMonth)!==D){next=date(Y,M,inc<0?0:inc);continue}if(sched.wm){firstDayOfMonth=getDay.call(nextDate(Y,M,1));wm=floor((D+firstDayOfMonth-1)/7+1);weeksInMonth=floor((daysInMonth+firstDayOfMonth-1)/7+1);if(((inc=range(wm,sched.wm,weeksInMonth))||weeksInMonth)!==wm){if(inc===0){next=date(Y,M,inc)}else{next=date(Y,M,(inc<0?inc+1:inc-1)*7-(firstDayOfMonth-1)-(inc>weeksInMonth&&getDay.call(oMonthEnd)<6?7:0)+(inc===weeksInMonth+1?getDay.call(oMonthEnd)+1:0)+(reverse?6:0))}continue}}if(sched.d&&(inc=range(d+1,sched.d,7))!==d+1){next=date(Y,M,D+(inc-1)-d);continue}if(sched.dc){dc=floor((D-1)/7)+1;if((inc=range(dc,sched.dc,0))!==dc){if(reverse){if(inc>0){next=date(Y,M+(inc<dc?0:-1),7+7*(inc-1));continue}else if(inc===0&&D<daysInMonth-6){next=date(Y,M,inc);continue}}else{if(inc>0){next=date(Y,M+(inc<dc?1:0),1+7*(inc-1));continue}else if(inc<1&&D<daysInMonth-6){next=date(Y,M,daysInMonth-6);continue}}}}h=getHour.call(next);m=getMin.call(next);s=getSec.call(next);t=pad(h)+":"+pad(m)+":"+pad(s);if(sched.ta){if(t<sched.ta[0]){if(reverse){next=date(Y,M,D-1)}else{x=sched.ta[0].split(":");next=date(Y,M,D,x[0],x[1],x[2])}continue}}if(sched.tb){if(t>=sched.tb[0]){if(reverse){x=sched.tb[0].split(":");next=date(Y,M,D,x[0],x[1],x[2]-1)}else{next=date(Y,M,D+1)}continue}}if(sched.h&&(inc=range(h,sched.h,24))!==h){next=date(Y,M,D,inc);continue}if(sched.m&&(inc=range(m,sched.m,60))!==m){next=date(Y,M,D,h,inc);continue}if(sched.s&&(inc=range(s,sched.s,60))!==s){next=date(Y,M,D,h,m,inc);continue}if(sched.t){if((inc=range(t,sched.t))!==t){x=inc.split(":");var dayInc=!reverse?t>inc?1:0:t<inc?-1:0;next=date(Y,M,D+dayInc,x[0],x[1],x[2]);continue}}break}return maxLoopCount>0?next:null};var after=function(start,sched){var yr=getYear.call(start)+getAfter(sched.aY),mt=getMonth.call(start)+getAfter(sched.aM),dt=getDate.call(start)+max(getAfter(sched.aD),getAfter(sched.ady),getAfter(sched.ad),getAfter(sched.awy)*7,getAfter(sched.awm)*7),hr=getHour.call(start)+getAfter(sched.ah),mn=getMin.call(start)+getAfter(sched.am),sc=getSec.call(start)+getAfter(sched.as);return nextDate(yr,mt,dt,hr,mn,sc)};var getAfter=function(constraint){return constraint&&constraint[0]?constraint[0]:0};var tick=function(date,backwards){return!backwards?new Date(date.getTime()+resolution*1e3):new Date(date.getTime()-resolution*1e3)};return{isValid:function(recur,date){date.setMilliseconds(0);var next=this.getNext(recur,date);return next?date.getTime()===next.getTime():false},get:function(recur,count,startDate,endDate,reverse){var occurrences=[],date;while(count-->0&&(date=!reverse?this.getNext(recur,date||startDate,endDate):this.getPrevious(recur,date||startDate,endDate))){occurrences.push(date);date=tick(date,reverse)}return occurrences},getNext:function(recur,startDate,endDate){var schedules=recur?recur.schedules||[]:[],exceptions=recur?recur.exceptions||[]:[],schedLen=schedules.length,exceptLen=exceptions.length,start=startDate||new Date,date;while(start){var tDate;if(endDate&&start.getTime()>endDate.getTime()){date=undefined;break}if(schedLen){for(var i=0;i<schedLen;i++){tDate=getNextForSchedule(schedules[i],start,endDate);if(tDate&&(!date||tDate.getTime()<date.getTime())){date=tDate}}}else{date=start}start=null;if(date&&exceptLen){tDate=this.getNextInvalid({schedules:exceptions},date);if(tDate.getTime()!==date.getTime()){start=tDate;date=undefined}}}return date},getNextInvalid:function(recur,startDate){var schedules=recur?recur.schedules||[]:[],exceptions=recur?recur.exceptions||[]:[],schedLen=schedules.length,exceptLen=exceptions.length,start=startDate||new Date;while(start&&this.isValid(recur,start)){var nextExcep,nextInvalid;for(var i=0;i<schedLen;i++){var tDate=getNextInvalidSchedule(schedules[i],start);if(tDate&&(!nextInvalid||tDate.getTime()>nextInvalid.getTime())){nextInvalid=tDate}}if(exceptLen){nextExcep=this.getNext({schedules:exceptions},start)}if(!nextInvalid&&!nextExcep){start=undefined}else{start=new Date(nextInvalid&&nextExcep?Math.min(nextInvalid.getTime(),nextExcep.getTime()):nextExcep||nextInvalid)}}return start},getPrevious:function(recur,startDate,endDate){var schedules=recur?recur.schedules||[]:[],exceptions={schedules:recur?recur.exceptions||[]:[]},end=startDate||new Date,date,tDate,i=schedules.length;if(endDate&&startDate.getTime()<endDate.getTime()){return null}if(i===0){date=end}else{while(i--){tDate=getNextForSchedule(schedules[i],end,endDate,true);if(!date||tDate>date){date=tDate}}}if(date&&exceptions.schedules.length>0&&this.isValid(exceptions,date)){date=this.getPrevious(recur,tick(date,true),endDate)}return date},exec:function(recur,startDate,callback,arg){var next=this.getNext(recur,tick(startDate));if(next){next=next.getTime()-(new Date).getTime();if(next>2147483647){exec=setTimeout(this.exec,2147483647,recur,startDate,callback,arg)}else{exec=setTimeout(this.handleExec,next,this,recur,callback,arg)}return true}},stopExec:function(){if(exec){clearTimeout(exec);exec=false}},handleExec:function(later,recur,callback,arg){callback(arg);if(exec){later.exec(recur,new Date,callback,arg)}}}};var root=typeof exports!=="undefined"&&exports!==null?exports:window;root.later=Later}).call(this);(function(){"use strict";var Recur=function(){var schedules=[],exceptions=[],cur,curArr=schedules,curName,values,every,after,applyMin,applyMax,i,last;var add=function(name,min,max){name=after?"a"+name:name;if(!cur){curArr.push({});cur=curArr[0]}if(!cur[name]){cur[name]=[]}curName=cur[name];if(every){values=[];for(i=min;i<=max;i+=every){values.push(i)}last={n:name,x:every,c:curName.length,m:max}}values=applyMin?[min]:applyMax?[max]:values;var length=values.length;for(i=0;i<length;i+=1){if(curName.indexOf(values[i])<0){curName.push(values[i])}}values=every=after=applyMin=applyMax=0};return{schedules:schedules,exceptions:exceptions,on:function(){values=arguments[0]instanceof Array?arguments[0]:arguments;return this},every:function(x){every=x;return this},after:function(x){after=true;values=[x];return this},first:function(){applyMin=1;return this},last:function(){applyMax=1;return this},at:function(){values=arguments;for(var i=0,len=values.length;i<len;i++){var split=values[i].split(":");if(split.length<3){values[i]+=":00"}}add("t");return this},afterTime:function(){values=arguments;for(var i=0,len=values.length;i<len;i++){var split=values[i].split(":");if(split.length<3){values[i]+=":00"}}add("ta");return this},beforeTime:function(){values=arguments;for(var i=0,len=values.length;i<len;i++){var split=values[i].split(":");if(split.length<3){values[i]+=":00"}}add("tb");return this},second:function(){add("s",0,59);return this},minute:function(){add("m",0,59);return this},hour:function(){add("h",0,23);return this},dayOfMonth:function(){add("D",1,applyMax?0:31);return this},dayOfWeek:function(){add("d",1,7);return this},onWeekend:function(){values=[1,7];return this.dayOfWeek()},onWeekday:function(){values=[2,3,4,5,6];return this.dayOfWeek()},dayOfWeekCount:function(){add("dc",1,applyMax?0:5);return this},dayOfYear:function(){add("dy",1,applyMax?0:366);return this},weekOfMonth:function(){add("wm",1,applyMax?0:5);return this},weekOfYear:function(){add("wy",1,applyMax?0:53);return this},month:function(){add("M",1,12);return this},year:function(){add("Y",1970,2450);return this},startingOn:function(start){return this.between(start,last.m)},between:function(start,end){cur[last.n]=cur[last.n].splice(0,last.c);every=last.x;add(last.n,start,end);return this},and:function(){cur=curArr[curArr.push({})-1];return this},except:function(){curArr=exceptions;cur=null;return this}}};var root=typeof exports!=="undefined"&&exports!==null?exports:window;root.recur=Recur}).call(this);if(!Array.prototype.indexOf){Array.prototype.indexOf=function(searchElement){"use strict";if(this==null){throw new TypeError}var t=Object(this);var len=t.length>>>0;if(len===0){return-1}var n=0;if(arguments.length>1){n=Number(arguments[1]);if(n!=n){n=0}else if(n!=0&&n!=Infinity&&n!=-Infinity){n=(n>0||-1)*Math.floor(Math.abs(n))}}if(n>=len){return-1}var k=n>=0?n:Math.max(len-Math.abs(n),0);for(;k<len;k++){if(k in t&&t[k]===searchElement){return k}}return-1}}if(!String.prototype.trim){String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}}