"undefined"!=typeofrequire&&(moment=require("moment")),function(a){functionb(b,d,e,g,h,i){if(this.rangeStart=a(b),this.rangeEnd=a(d),this.exclusions=g,this.inclusions=h,this.useIsoWeekday=1==i,this.rangeStart.isAfter(this.rangeEnd))thrownewc("rangeStart is after rangeEnd");this.weekdays=f(e,this.useIsoWeekday)}functionc(a){this.message=a,this.name="WeekDayCalcException"}functiond(b,c,d,e,g){this.rangeStart=a(b),this.useIsoWeekday=1==g,this.exclusions=d,this.inclusions=e,this.weekdays=f(c,this.useIsoWeekday)}functione(a){this.message=a,this.name="DaysSetConverterException"}b.prototype.calculate=function(){vara=0,b=this.rangeStart.clone().endOf("week"),c=this.rangeEnd.clone().startOf("week");if(c.diff(b,"days")<30||this.exclusions||this.inclusions)a=this.calculateIterative(this.rangeStart,this.rangeEnd,this.weekdays,this.exclusions,this.inclusions);else{vard=Math.round(c.diff(b,"weeks",!0));a+=d*this.weekdays.length,a+=this.calculateIterative(this.rangeStart,b,this.weekdays),a+=this.calculateIterative(c,this.rangeEnd,this.weekdays)}returna},b.prototype.calculateIterative=function(a,b,c,d,e){for(varf=0,h=a.clone(),i=g(d),j=g(e);h.valueOf()<=b.valueOf();){vark=this.useIsoWeekday?"isoWeekday":"weekday",l=h.format("YYYY-MM-DD"),m=0!=j.length&&j.indexOf(l)>=0;(m||c.indexOf(h[k]())>=0&&(0==i.length||i.indexOf(l)<0))&&f++,h.add(1,"day")}returnf},Function.prototype.construct=function(a){varb=this,c=function(){b.apply(this,a)};returnc.prototype=b.prototype,newc},c.prototype=newError,b.prototype.WeekDayCalcException=c,d.prototype.calculate=function(a){varb=a,c=this.rangeStart.clone(),d=g(this.exclusions),e=g(this.inclusions),f=this.useIsoWeekday?"isoWeekday":"weekday";if(b>=0)for(;b>0;){c.add(1,"day");varh=0!=e.length&&e.indexOf(c.format("YYYY-MM-DD"))>=0;(h||this.weekdays.indexOf(c[f]())>=0&&(0==d.length||d.indexOf(c.format("YYYY-MM-DD"))<0))&&b--}elsefor(;b<0;){c.subtract(1,"day");varh=0!=e.length&&e.indexOf(c.format("YYYY-MM-DD"))>=0;(h||this.weekdays.indexOf(c[f]())>=0&&(0==d.length||d.indexOf(c.format("YYYY-MM-DD"))<0))&&b++}returnc},e.prototype=newError,d.prototype.DaysSetConverterException=e;varf=function(b,d){vare=[];if(!b)thrownewc("weekdays must be defined");if(b.length>7)thrownewc("Weekdays array exceeding week length of 7 days");for(varf=0;f<b.length;f++){varg=b[f];if(d){if(isNaN(g))thrownewc("isoWeekDayCalc accepts weekdays as numbers only, try using weekdayCalc if you need a locale aware behaviour");if(g<1||g>7)thrownewc("The weekday is out of 1 to 7 range")}elseif(isNaN(g))g=a().day(g).weekday();elseif(g<0||g>6)thrownewc("The weekday is out of 0 to 6 range");if(e.indexOf(g)>=0)thrownewc("Weekdays set contains duplicate weekday");e.push(g)}returne},g=function(b){varc=[];if(b)for(vard=0,e=b.length;d<e;d++)c.push(a(b[d]).format("YYYY-MM-DD"));returnc};b.calculateWeekdays=function(d,e,f){varg,h,i,j,k;switch(f=!!f,e.length){case5:j=e[3],k=e[4];case4:j=e[3];case3:g=a(e[0]).startOf("day"),h=a(e[1]).endOf("day"),i=e[2];break;case2:g=d,h=e[0],i=e[1];break;case1:varl=e[0];l&&l.rangeEnd&&l.weekdays?(g=l.rangeStart?a(l.rangeStart).startOf("day"):d,h=a(l.rangeEnd).endOf("day"),i=l.weekdays,j=l.exclusions,k=l.inclusions):(g=d.clone().startOf("year"),h=d.clone().endOf("year"),i=l);break;default:newc("unexpected arguments length "+e.length+". Expecting 1 to 4 args")}if(g.isAfter(h)){varm=g.clone();g=h.clone(),h=m}varn=b.construct([g,h,i,j,k,f]);returnn.calculate()},d.calculateDate=function(a,b,c){varf,g,h,i;c=!!c;switch(b.length){case4:g=b[2],h=b[3];case3:g=b[2];case2:f=b[0],i=b[1];break;case1:varj=b[0];if(!j||void0==j.days&&void0==j.workdays)f=j;else{if(void0!=j.days&&void0!=j.workdays)thrownewe("days and weekdays args should not be used together, because weekdays is an alias of days");f=j.days?j.days:j.workdays,i=j.weekdays?j.weekdays:[1,2,3,4,5],g=j.exclusions,h=j.inclusions}break;default:newe("unexpected arguments length "+b.length+". Expecting 1 to 3 args")}vark=d.construct([a,i,g,h,c]);returnk.calculate(f)},a.fn.weekdayCalc=function(){returnb.calculateWeekdays(this,arguments)},a.fn.isoWeekdayCalc=function(){returnb.calculateWeekdays(this,arguments,!0)},a.fn.addWorkdays=function(a,b,c){returnd.calculateDate(this,[a,[1,2,3,4,5],b,c])},a.fn.workdaysToCalendarDays=function(a,b,c){vare=d.calculateDate(this,[a,[1,2,3,4,5],b,c]);returne.diff(this,"days")},a.fn.addWeekdaysFromSet=function(){returnd.calculateDate(this,arguments)},a.fn.weekdaysFromSetToCalendarDays=function(){vara=d.calculateDate(this,arguments);returna.diff(this,"days")},a.fn.isoAddWeekdaysFromSet=function(){returnd.calculateDate(this,arguments,!0)},a.fn.isoWeekdaysFromSetToCalendarDays=function(){vara=d.calculateDate(this,arguments,!0);returna.diff(this,"days")},"object"==typeofexports&&"undefined"!=typeofmodule?module.exports=b:"function"==typeofdefine&&define.amd?define(b):this.WeekDayCalc=b}(moment);