diff --git a/build/ical.js b/build/ical.js index e3481e2d..b65d1820 100644 --- a/build/ical.js +++ b/build/ical.js @@ -6974,12 +6974,26 @@ ICAL.RecurIterator = (function() { throw new Error("BYYEARDAY may only appear in YEARLY rules"); } + + this.sort_bypart_rules("BYSECOND", parts); this.last.second = this.setup_defaults("BYSECOND", "SECONDLY", this.dtstart.second); + + this.sort_bypart_rules("BYMINUTE", parts); this.last.minute = this.setup_defaults("BYMINUTE", "MINUTELY", this.dtstart.minute); + + this.sort_bypart_rules("BYHOUR", parts); this.last.hour = this.setup_defaults("BYHOUR", "HOURLY", this.dtstart.hour); - this.last.day = this.setup_defaults("BYMONTHDAY", "DAILY", this.dtstart.day); + + this.sort_bypart_rules("BYMONTH", parts); this.last.month = this.setup_defaults("BYMONTH", "MONTHLY", this.dtstart.month); + //setting day after month, as sorting BYMONTHDAY will differ based on the month + //-2 < 28 in Feb, -2 > 28 in march + this.sort_bypart_rules("BYMONTHDAY", parts); + this.last.day = this.setup_defaults("BYMONTHDAY", "DAILY", this.dtstart.day); + + this.sort_bypart_rules("BYYEARDAY", parts); + if (this.rule.freq == "WEEKLY") { if ("BYDAY" in parts) { var bydayParts = this.ruleDayOfWeek(parts.BYDAY[0]); @@ -8063,6 +8077,27 @@ ICAL.RecurIterator = (function() { return false; }, + sort_bypart_rules: function icalrecur_sort_bypart(aPartName, aParts) { + if (aPartName in aParts) { + var offset = 0; + if (aPartName == "BYYEARDAY") { + offset = ICAL.Time.isLeapYear(this.last.year)? 367 : 366; + } else if (aPartName == "BYMONTHDAY") { + offset = ICAL.Time.daysInMonth(this.last.month, this.last.year) + 1; + } + var comparator = function(a, b) { + if (a < 0) { + a += offset; + } + if (b < 0) { + b += offset; + } + return a - b; + }; + aParts[aPartName].sort(comparator); + } + }, + sort_byday_rules: function icalrecur_sort_byday_rules(aRules, aWeekStart) { for (var i = 0; i < aRules.length; i++) { for (var j = 0; j < i; j++) { diff --git a/build/ical.min.js b/build/ical.min.js index a025f385..dafe5cad 100644 --- a/build/ical.min.js +++ b/build/ical.min.js @@ -1,2 +1,2 @@ -"object"==typeof module?ICAL=module.exports:"object"!=typeof ICAL&&(this.ICAL={}),ICAL.foldLength=75,ICAL.newLineChar="\r\n",ICAL.helpers={updateTimezones:function(t){var e,n,r,i,a,s;if(!t||"vcalendar"!==t.name)return t;for(e=t.getAllSubcomponents(),n=[],r={},a=0;a0&&"\\"===t[n-1]))return n;n+=1}return-1},binsearchInsert:function(t,e,n){if(!t.length)return 0;for(var r,i,a=0,s=t.length-1;a<=s;)if(r=a+Math.floor((s-a)/2),(i=n(e,t[r]))<0)s=r-1;else{if(!(i>0))break;a=r+1}return i<0?r:i>0?r+1:r},dumpn:function(){ICAL.debug&&("undefined"!=typeof console&&"log"in console?ICAL.helpers.dumpn=function(t){console.log(t)}:ICAL.helpers.dumpn=function(t){dump(t+"\n")},ICAL.helpers.dumpn(arguments[0]))},clone:function(t,e){if(t&&"object"==typeof t){if(t instanceof Date)return new Date(t.getTime());if("clone"in t)return t.clone();if(Array.isArray(t)){for(var n=[],r=0;r11?t:t.substr(0,4)+t.substr(5,2)+t.substr(8,2)}},"date-time":{fromICAL:function(t){var e=t.substr(0,4)+"-"+t.substr(4,2)+"-"+t.substr(6,2)+"T"+t.substr(9,2)+":"+t.substr(11,2)+":"+t.substr(13,2);return t[15]&&"Z"===t[15]&&(e+="Z"),e},toICAL:function(t){if(t.length<19)return t;var e=t.substr(0,4)+t.substr(5,2)+t.substr(8,5)+t.substr(14,2)+t.substr(17,2);return t[19]&&"Z"===t[19]&&(e+="Z"),e},decorate:function(t,e){return ICAL.Time.fromDateTimeString(t,e)},undecorate:function(t){return t.toString()}},duration:{decorate:function(t){return ICAL.Duration.fromString(t)},undecorate:function(t){return t.toString()}},period:{fromICAL:function(t){var e=t.split("/");return e[0]=T["date-time"].fromICAL(e[0]),ICAL.Duration.isValueString(e[1])||(e[1]=T["date-time"].fromICAL(e[1])),e},toICAL:function(t){return t[0]=T["date-time"].toICAL(t[0]),ICAL.Duration.isValueString(t[1])||(t[1]=T["date-time"].toICAL(t[1])),t.join("/")},decorate:function(t,e){return ICAL.Period.fromJSON(t,e)},undecorate:function(t){return t.toJSON()}},recur:{fromICAL:function(t){return ICAL.Recur._stringToData(t,!0)},toICAL:function(t){var e="";for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)){var r=t[n];"until"==n?r=r.length>10?T["date-time"].toICAL(r):T.date.toICAL(r):"wkst"==n?"number"==typeof r&&(r=ICAL.Recur.numericDayToIcalDay(r)):Array.isArray(r)&&(r=r.join(",")),e+=n.toUpperCase()+"="+r+";"}return e.substr(0,e.length-1)},decorate:function(t){return ICAL.Recur.fromData(t)},undecorate:function(t){return t.toJSON()}},time:{fromICAL:function(t){if(t.length<6)return t;var e=t.substr(0,2)+":"+t.substr(2,2)+":"+t.substr(4,2);return"Z"===t[6]&&(e+="Z"),e},toICAL:function(t){if(t.length<8)return t;var e=t.substr(0,2)+t.substr(3,2)+t.substr(6,2);return"Z"===t[8]&&(e+="Z"),e}}}),L=ICAL.helpers.extend(A,{action:o,attach:{defaultType:"uri"},attendee:{defaultType:"cal-address"},calscale:o,class:o,comment:o,completed:d,contact:o,created:d,description:o,dtend:l,dtstamp:d,dtstart:l,due:l,duration:{defaultType:"duration"},exdate:{defaultType:"date-time",allowedTypes:["date-time","date"],multiValue:","},exrule:p,freebusy:{defaultType:"period",multiValue:","},geo:{defaultType:"float",structuredValue:";"},"last-modified":d,location:o,method:o,organizer:{defaultType:"cal-address"},"percent-complete":c,priority:c,prodid:o,"related-to":o,repeat:c,rdate:{defaultType:"date-time",allowedTypes:["date-time","date","period"],multiValue:",",detectType:function(t){return-1!==t.indexOf("/")?"period":-1===t.indexOf("T")?"date":"date-time"}},"recurrence-id":l,resources:u,"request-status":h,rrule:p,sequence:c,status:o,summary:o,transp:o,trigger:{defaultType:"duration",allowedTypes:["duration","date-time"]},tzoffsetfrom:m,tzoffsetto:m,tzurl:f,tzid:o,tzname:o}),_=ICAL.helpers.extend(C,{text:t(a,s),uri:t(a,s),date:{decorate:function(t){return ICAL.VCardTime.fromDateAndOrTimeString(t,"date")},undecorate:function(t){return t.toString()},fromICAL:function(t){return 8==t.length?T.date.fromICAL(t):"-"==t[0]&&6==t.length?t.substr(0,4)+"-"+t.substr(4):t},toICAL:function(t){return 10==t.length?T.date.toICAL(t):"-"==t[0]&&7==t.length?t.substr(0,4)+t.substr(5):t}},time:{decorate:function(t){return ICAL.VCardTime.fromDateAndOrTimeString("T"+t,"time")},undecorate:function(t){return t.toString()},fromICAL:function(t){var e=_.time._splitZone(t,!0),n=e[0],r=e[1];return 6==r.length?r=r.substr(0,2)+":"+r.substr(2,2)+":"+r.substr(4,2):4==r.length&&"-"!=r[0]?r=r.substr(0,2)+":"+r.substr(2,2):5==r.length&&(r=r.substr(0,3)+":"+r.substr(3,2)),5!=n.length||"-"!=n[0]&&"+"!=n[0]||(n=n.substr(0,3)+":"+n.substr(3)),r+n},toICAL:function(t){var e=_.time._splitZone(t),n=e[0],r=e[1];return 8==r.length?r=r.substr(0,2)+r.substr(3,2)+r.substr(6,2):5==r.length&&"-"!=r[0]?r=r.substr(0,2)+r.substr(3,2):6==r.length&&(r=r.substr(0,3)+r.substr(4,2)),6!=n.length||"-"!=n[0]&&"+"!=n[0]||(n=n.substr(0,3)+n.substr(4)),r+n},_splitZone:function(t,e){var n,r,i=t.length-1,a=t.length-(e?5:6),s=t[a];return"Z"==t[i]?(n=t[i],r=t.substr(0,i)):t.length>6&&("-"==s||"+"==s)?(n=t.substr(a),r=t.substr(0,a)):(n="",r=t),[n,r]}},"date-time":{decorate:function(t){return ICAL.VCardTime.fromDateAndOrTimeString(t,"date-time")},undecorate:function(t){return t.toString()},fromICAL:function(t){return _["date-and-or-time"].fromICAL(t)},toICAL:function(t){return _["date-and-or-time"].toICAL(t)}},"date-and-or-time":{decorate:function(t){return ICAL.VCardTime.fromDateAndOrTimeString(t,"date-and-or-time")},undecorate:function(t){return t.toString()},fromICAL:function(t){var e=t.split("T");return(e[0]?_.date.fromICAL(e[0]):"")+(e[1]?"T"+_.time.fromICAL(e[1]):"")},toICAL:function(t){var e=t.split("T");return _.date.toICAL(e[0])+(e[1]?"T"+_.time.toICAL(e[1]):"")}},timestamp:T["date-time"],"language-tag":{matches:/^[a-zA-Z0-9-]+$/}}),v={type:{valueType:"text",multiValue:","},value:{values:["text","uri","date","time","date-time","date-and-or-time","timestamp","boolean","integer","float","utc-offset","language-tag"],allowXName:!0,allowIanaToken:!0}},g=ICAL.helpers.extend(A,{adr:{defaultType:"text",structuredValue:";",multiValue:","},anniversary:y,bday:y,caladruri:f,caluri:f,clientpidmap:h,email:o,fburl:f,fn:o,gender:h,geo:f,impp:f,key:f,kind:o,lang:{defaultType:"language-tag"},logo:f,member:f,n:{defaultType:"text",structuredValue:";",multiValue:","},nickname:u,note:o,org:{defaultType:"text",structuredValue:";"},photo:f,related:f,rev:{defaultType:"timestamp"},role:o,sound:f,source:f,tel:{defaultType:"uri",allowedTypes:["uri","text"]},title:o,tz:{defaultType:"text",allowedTypes:["text","utc-offset","uri"]},xml:o}),D=ICAL.helpers.extend(C,{binary:T.binary,date:_.date,"date-time":_["date-time"],"phone-number":{},uri:T.uri,text:T.text,time:T.time,vcard:T.text,"utc-offset":{toICAL:function(t){return t.substr(0,7)},fromICAL:function(t){return t.substr(0,7)},decorate:function(t){return ICAL.UtcOffset.fromString(t)},undecorate:function(t){return t.toString()}}}),b={type:{valueType:"text",multiValue:","},value:{values:["text","uri","date","date-time","phone-number","time","boolean","integer","float","utc-offset","vcard","binary"],allowXName:!0,allowIanaToken:!0}},Y=ICAL.helpers.extend(A,{fn:o,n:{defaultType:"text",structuredValue:";",multiValue:","},nickname:u,photo:{defaultType:"binary",allowedTypes:["binary","uri"]},bday:{defaultType:"date-time",allowedTypes:["date-time","date"],detectType:function(t){return-1===t.indexOf("T")?"date":"date-time"}},adr:{defaultType:"text",structuredValue:";",multiValue:","},label:o,tel:{defaultType:"phone-number"},email:o,mailer:o,tz:{defaultType:"utc-offset",allowedTypes:["utc-offset","text"]},geo:{defaultType:"float",structuredValue:";"},title:o,role:o,logo:{defaultType:"binary",allowedTypes:["binary","uri"]},agent:{defaultType:"vcard",allowedTypes:["vcard","text","uri"]},org:h,note:u,prodid:o,rev:{defaultType:"date-time",allowedTypes:["date-time","date"],detectType:function(t){return-1===t.indexOf("T")?"date":"date-time"}},"sort-string":o,sound:{defaultType:"binary",allowedTypes:["binary","uri"]},class:o,key:{defaultType:"binary",allowedTypes:["binary","text"]}}),O={value:T,param:I,property:L},S={value:_,param:v,property:g},w={value:D,param:b,property:Y},E={defaultSet:O,defaultType:"unknown",components:{vcard:S,vcard3:w,vevent:O,vtodo:O,vjournal:O,valarm:O,vtimezone:O,daylight:O,standard:O},icalendar:O,vcard:S,vcard3:w,getDesignSet:function(t){return t&&t in E.components?E.components[t]:E.defaultSet}};return E}(),ICAL.stringify=function(){"use strict";function t(n){"string"==typeof n[0]&&(n=[n]);for(var r=0,i=n.length,a="";r0&&("version"!==r[1][0][0]||"4.0"!==r[1][0][3])&&(c="vcard3"),i=i||n.getDesignSet(c);u1)throw new t("invalid ical body. component began but did not end");return r=null,1==i.length?i[0]:i}var n=/[^ \t]/,r=ICAL.design,i=ICAL.helpers;t.prototype=Error.prototype,e.property=function(t,n){var i={component:[[],[]],designSet:n||r.defaultSet};return e._handleContentLine(t,i),i.component[1][0]},e.component=function(t){return e(t)},e.ParserError=t,e._handleContentLine=function(n,i){var a,s,o,u,h=n.indexOf(":"),c=n.indexOf(";"),l={};-1!==c&&-1!==h&&c>h&&(c=-1);var d;if(-1!==c){if(o=n.substring(0,c).toLowerCase(),-1==(d=e._parseParameters(n.substring(c),0,i.designSet))[2])throw new t("Invalid parameters in '"+n+"'");if(l=d[0],a=d[1].length+d[2]+c,-1===(s=n.substring(a).indexOf(":")))throw new t("Missing parameter value in '"+n+"'");u=n.substring(a+s+1)}else{if(-1===h)throw new t('invalid line (no token ";" or ":") "'+n+'"');if(o=n.substring(0,h).toLowerCase(),u=n.substring(h+1),"begin"===o){var f=[u.toLowerCase(),[],[]];return 1===i.stack.length?i.component.push(f):i.component[2].push(f),i.stack.push(i.component),i.component=f,void(i.designSet||(i.designSet=r.getDesignSet(i.component[0])))}if("end"===o)return void(i.component=i.stack.pop())}var m,p,y=!1,A=!1;o in i.designSet.property&&("multiValue"in(p=i.designSet.property[o])&&(y=p.multiValue),"structuredValue"in p&&(A=p.structuredValue),u&&"detectType"in p&&(m=p.detectType(u))),m||(m="value"in l?l.value.toLowerCase():p?p.defaultType:"unknown"),delete l.value;var C;y&&A?C=[o,l,m,u=e._parseMultiValue(u,A,m,[],y,i.designSet,A)]:y?(C=[o,l,m],e._parseMultiValue(u,y,m,C,null,i.designSet,!1)):C=A?[o,l,m,u=e._parseMultiValue(u,A,m,[],null,i.designSet,A)]:[o,l,m,u=e._parseValue(u,m,i.designSet,!1)],"vcard"!==i.component[0]||0!==i.component[1].length||"version"===o&&"4.0"===u||(i.designSet=r.getDesignSet("vcard3")),i.component[1].push(C)},e._parseValue=function(t,e,n,r){return e in n.value&&"fromICAL"in n.value[e]?n.value[e].fromICAL(t,r):t},e._parseParameters=function(n,r,a){for(var s,o,u,h,c,l,d=r,f=0,m={},p=-1;!1!==f&&-1!==(f=i.unescapedIndexOf(n,"=",f+1));){if(0==(s=n.substr(d+1,f-d-1)).length)throw new t("Empty parameter name in '"+n+"'");if(h=(o=s.toLowerCase())in a.param&&a.param[o].valueType?a.param[o].valueType:"text",o in a.param&&(c=a.param[o].multiValue,a.param[o].multiValueSeparateDQuote&&(l=e._rfc6868Escape('"'+c+'"'))),'"'===n[f+1]){if(p=f+2,f=i.unescapedIndexOf(n,'"',p),c&&-1!=f)for(var y=!0;y;)n[f+1]==c&&'"'==n[f+2]?f=i.unescapedIndexOf(n,'"',f+3):y=!1;if(-1===f)throw new t('invalid line (no matching double quote) "'+n+'"');u=n.substr(p,f-p),-1===(d=i.unescapedIndexOf(n,";",f))&&(f=!1)}else{p=f+1;var A=i.unescapedIndexOf(n,";",p),C=i.unescapedIndexOf(n,":",p);-1!==C&&A>C?(A=C,f=!1):-1===A?(A=-1===C?n.length:C,f=!1):(d=A,f=A),u=n.substr(p,A-p)}if(u=e._rfc6868Escape(u),c){var I=l||c;m[o]=e._parseMultiValue(u,I,h,[],null,a)}else m[o]=e._parseValue(u,h,a)}return[m,u,p]},e._rfc6868Escape=function(t){return t.replace(/\^['n^]/g,function(t){return a[t]})};var a={"^'":'"',"^n":"\n","^^":"^"};return e._parseMultiValue=function(t,n,r,a,s,o,u){var h,c=0,l=0;if(0===n.length)return t;for(;-1!==(c=i.unescapedIndexOf(t,n,l));)h=t.substr(l,c-l),h=s?e._parseMultiValue(h,s,r,[],null,o,u):e._parseValue(h,r,o,u),a.push(h),l=c+n.length;return h=t.substr(l),h=s?e._parseMultiValue(h,s,r,[],null,o,u):e._parseValue(h,r,o,u),a.push(h),1==a.length?a[0]:a},e._eachLine=function(t,e){var r,i,a,s=t.length,o=t.search(n),u=o;do{a=(u=t.indexOf("\n",o)+1)>1&&"\r"===t[u-2]?2:1,0===u&&(u=s,a=0)," "===(i=t[o])||"\t"===i?r+=t.substr(o+1,u-o-(a+1)):(r&&e(null,r),r=t.substr(o,u-o-a)),o=u}while(u!==s);(r=r.trim()).length&&e(null,r)},e}(),ICAL.Component=function(){"use strict";function t(t,e){"string"==typeof t&&(t=[t,[],[]]),this.jCal=t,this.parent=e||null}var e=0;return t.prototype={_hydratedPropertyCount:0,_hydratedComponentCount:0,get name(){return this.jCal[e]},get _designSet(){return this.parent&&this.parent._designSet||ICAL.design.getDesignSet(this.name)},_hydrateComponent:function(e){if(this._components||(this._components=[],this._hydratedComponentCount=0),this._components[e])return this._components[e];var n=new t(this.jCal[2][e],this);return this._hydratedComponentCount++,this._components[e]=n},_hydrateProperty:function(t){if(this._properties||(this._properties=[],this._hydratedPropertyCount=0),this._properties[t])return this._properties[t];var e=new ICAL.Property(this.jCal[1][t],this);return this._hydratedPropertyCount++,this._properties[t]=e},getFirstSubcomponent:function(t){if(t){for(var n=0,r=this.jCal[2],i=r.length;n=0;s--)r&&a[s][e]!==r||this._removeObjectByIndex(t,i,s)},addSubcomponent:function(t){this._components||(this._components=[],this._hydratedComponentCount=0),t.parent&&t.parent.removeSubcomponent(t);var e=this.jCal[2].push(t.jCal);return this._components[e-1]=t,this._hydratedComponentCount++,t.parent=this,t},removeSubcomponent:function(t){var e=this._removeObject(2,"_components",t);return e&&this._hydratedComponentCount--,e},removeAllSubcomponents:function(t){var e=this._removeAllObjects(2,"_components",t);return this._hydratedComponentCount=0,e},addProperty:function(t){if(!(t instanceof ICAL.Property))throw new TypeError("must instance of ICAL.Property");this._properties||(this._properties=[],this._hydratedPropertyCount=0),t.parent&&t.parent.removeProperty(t);var e=this.jCal[1].push(t.jCal);return this._properties[e-1]=t,this._hydratedPropertyCount++,t.parent=this,t},addPropertyWithValue:function(t,e){var n=new ICAL.Property(t);return n.setValue(e),this.addProperty(n),n},updatePropertyWithValue:function(t,e){var n=this.getFirstProperty(t);return n?n.setValue(e):n=this.addPropertyWithValue(t,e),n},removeProperty:function(t){var e=this._removeObject(1,"_properties",t);return e&&this._hydratedPropertyCount--,e},removeAllProperties:function(t){var e=this._removeAllObjects(1,"_properties",t);return this._hydratedPropertyCount=0,e},toJSON:function(){return this.jCal},toString:function(){return ICAL.stringify.component(this.jCal,this._designSet)}},t.fromString=function(e){return new t(ICAL.parse.component(e))},t}(),ICAL.Property=function(){"use strict";function t(t,e){this._parent=e||null,"string"==typeof t?(this.jCal=[t,{},r.defaultType],this.jCal[n]=this.getDefaultType()):this.jCal=t,this._updateType()}var e=0,n=2,r=ICAL.design;return t.prototype={get type(){return this.jCal[n]},get name(){return this.jCal[e]},get parent(){return this._parent},set parent(t){var e=!this._parent||t&&t._designSet!=this._parent._designSet;return this._parent=t,this.type==r.defaultType&&e&&(this.jCal[n]=this.getDefaultType(),this._updateType()),t},get _designSet(){return this.parent?this.parent._designSet:r.defaultSet},_updateType:function(){var t=this._designSet;if(this.type in t.value){t.value[this.type];"decorate"in t.value[this.type]?this.isDecorated=!0:this.isDecorated=!1,this.name in t.property&&(this.isMultiValue="multiValue"in t.property[this.name],this.isStructuredValue="structuredValue"in t.property[this.name])}},_hydrateValue:function(t){return this._values&&this._values[t]?this._values[t]:this.jCal.length<=3+t?null:this.isDecorated?(this._values||(this._values=[]),this._values[t]=this._decorate(this.jCal[3+t])):this.jCal[3+t]},_decorate:function(t){return this._designSet.value[this.type].decorate(t,this)},_undecorate:function(t){return this._designSet.value[this.type].undecorate(t,this)},_setDecoratedValue:function(t,e){this._values||(this._values=[]),"object"==typeof t&&"icaltype"in t?(this.jCal[3+e]=this._undecorate(t),this._values[e]=t):(this.jCal[3+e]=t,this._values[e]=this._decorate(t))},getParameter:function(t){return t in this.jCal[1]?this.jCal[1][t]:void 0},setParameter:function(t,e){var n=t.toLowerCase();"string"==typeof e&&n in this._designSet.param&&"multiValue"in this._designSet.param[n]&&(e=[e]),this.jCal[1][t]=e},removeParameter:function(t){delete this.jCal[1][t]},getDefaultType:function(){var t=this.jCal[e],n=this._designSet;if(t in n.property){var i=n.property[t];if("defaultType"in i)return i.defaultType}return r.defaultType},resetType:function(t){this.removeAllValues(),this.jCal[n]=t,this._updateType()},getFirstValue:function(){return this._hydrateValue(0)},getValues:function(){var t=this.jCal.length-3;if(t<1)return[];for(var e=0,n=[];e0&&"object"==typeof t[0]&&"icaltype"in t[0]&&this.resetType(t[0].icaltype),this.isDecorated)for(;nn)-(n>e)},_normalize:function(){for(var t=this.toSeconds(),e=this.factor;t<-43200;)t+=97200;for(;t>50400;)t-=97200;this.fromSeconds(t),0==t&&(this.factor=e)},toICALString:function(){return ICAL.design.icalendar.value["utc-offset"].toICAL(this.toString())},toString:function(){return(1==this.factor?"+":"-")+ICAL.helpers.pad2(this.hours)+":"+ICAL.helpers.pad2(this.minutes)}},t.fromString=function(t){var e={};return e.factor="+"===t[0]?1:-1,e.hours=ICAL.helpers.strictParseInt(t.substr(1,2)),e.minutes=ICAL.helpers.strictParseInt(t.substr(4,2)),new ICAL.UtcOffset(e)},t.fromSeconds=function(e){var n=new t;return n.fromSeconds(e),n},t}(),ICAL.Binary=function(){function t(t){this.value=t}return t.prototype={icaltype:"binary",decodeValue:function(){return this._b64_decode(this.value)},setEncodedValue:function(t){this.value=this._b64_encode(t)},_b64_encode:function(t){var e,n,r,i,a,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,u=0,h="",c=[];if(!t)return t;do{e=(a=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,n=a>>12&63,r=a>>6&63,i=63&a,c[u++]=s.charAt(e)+s.charAt(n)+s.charAt(r)+s.charAt(i)}while(o>16&255,n=s>>8&255,r=255&s,c[h++]=64==i?String.fromCharCode(e):64==a?String.fromCharCode(e,n):String.fromCharCode(e,n,r)}while(un)-(e=0?r=n:i=-1,-1==i&&-1!=r)break;if((n+=i)<0)return 0;if(n>=this.changes.length)break}var s=this.changes[r];if(s.utcOffset-s.prevUtcOffset<0&&r>0){var o=ICAL.helpers.clone(s,!0);if(ICAL.Timezone.adjust_change(o,0,0,0,o.prevUtcOffset),ICAL.Timezone._compare_change_fn(e,o)<0){var u=this.changes[r-1];0!=s.is_daylight&&0==u.is_daylight&&(s=u)}}return s.utcOffset},_findNearbyChange:function(t){var e=ICAL.helpers.binsearchInsert(this.changes,t,ICAL.Timezone._compare_change_fn);return e>=this.changes.length?this.changes.length-1:e},_ensureCoverage:function(t){if(-1==ICAL.Timezone._minimumExpansionYear){var e=ICAL.Time.now();ICAL.Timezone._minimumExpansionYear=e.year}var n=t;if(nICAL.Timezone.MAX_YEAR&&(n=ICAL.Timezone.MAX_YEAR),!this.changes.length||this.expandedUntilYeare)&&l);)a.year=l.year,a.month=l.month,a.day=l.day,a.hour=l.hour,a.minute=l.minute,a.second=l.second,a.isDate=l.isDate,ICAL.Timezone.adjust_change(a,0,0,0,-a.prevUtcOffset),n.push(a)}}else(a=i()).year=s.year,a.month=s.month,a.day=s.day,a.hour=s.hour,a.minute=s.minute,a.second=s.second,ICAL.Timezone.adjust_change(a,0,0,0,-a.prevUtcOffset),n.push(a);return n},toString:function(){return this.tznames?this.tznames:this.tzid}},ICAL.Timezone._compare_change_fn=function(t,e){return t.yeare.year?1:t.monthe.month?1:t.daye.day?1:t.houre.hour?1:t.minutee.minute?1:t.seconde.second?1:0},ICAL.Timezone.convert_time=function(t,e,n){if(t.isDate||e.tzid==n.tzid||e==ICAL.Timezone.localTimezone||n==ICAL.Timezone.localTimezone)return t.zone=n,t;var r=e.utcOffset(t);return t.adjust(0,0,0,-r),r=n.utcOffset(t),t.adjust(0,0,0,r),null},ICAL.Timezone.fromData=function(t){return(new ICAL.Timezone).fromData(t)},ICAL.Timezone.utcTimezone=ICAL.Timezone.fromData({tzid:"UTC"}),ICAL.Timezone.localTimezone=ICAL.Timezone.fromData({tzid:"floating"}),ICAL.Timezone.adjust_change=function(t,e,n,r,i){return ICAL.Time.prototype.adjust.call(t,e,n,r,i,t)},ICAL.Timezone._minimumExpansionYear=-1,ICAL.Timezone.MAX_YEAR=2035,ICAL.Timezone.EXTRA_COVERAGE=5}(),ICAL.TimezoneService=function(){var t,e={reset:function(){t=Object.create(null);var e=ICAL.Timezone.utcTimezone;t.Z=e,t.UTC=e,t.GMT=e},has:function(e){return!!t[e]},get:function(e){return t[e]},register:function(e,n){if(e instanceof ICAL.Component&&"vtimezone"===e.name&&(e=(n=new ICAL.Timezone(e)).tzid),!(n instanceof ICAL.Timezone))throw new TypeError("timezone must be ICAL.Timezone or ICAL.Component");t[e]=n},remove:function(e){return delete t[e]}};return e.reset(),e}(),ICAL.Time=function(t,e){this.wrappedJSObject=this;var n=this._time=Object.create(null);n.year=0,n.month=1,n.day=1,n.hour=0,n.minute=0,n.second=0,n.isDate=!1,this.fromData(t,e)},ICAL.Time._dowCache={},ICAL.Time._wnCache={},ICAL.Time.prototype={icalclass:"icaltime",_cachedUnixTime:null,get icaltype(){return this.isDate?"date":"date-time"},zone:null,_pendingNormalization:!1,clone:function(){return new ICAL.Time(this._time,this.zone)},reset:function(){this.fromData(ICAL.Time.epochTime),this.zone=ICAL.Timezone.utcTimezone},resetTo:function(t,e,n,r,i,a,s){this.fromData({year:t,month:e,day:n,hour:r,minute:i,second:a,zone:s})},fromJSDate:function(t,e){return t?e?(this.zone=ICAL.Timezone.utcTimezone,this.year=t.getUTCFullYear(),this.month=t.getUTCMonth()+1,this.day=t.getUTCDate(),this.hour=t.getUTCHours(),this.minute=t.getUTCMinutes(),this.second=t.getUTCSeconds()):(this.zone=ICAL.Timezone.localTimezone,this.year=t.getFullYear(),this.month=t.getMonth()+1,this.day=t.getDate(),this.hour=t.getHours(),this.minute=t.getMinutes(),this.second=t.getSeconds()):this.reset(),this._cachedUnixTime=null,this},fromData:function(t,e){if(t)for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)){if("icaltype"===n)continue;this[n]=t[n]}if(e&&(this.zone=e),!t||"isDate"in t?t&&"isDate"in t&&(this.isDate=t.isDate):this.isDate=!("hour"in t),t&&"timezone"in t){var r=ICAL.TimezoneService.get(t.timezone);this.zone=r||ICAL.Timezone.localTimezone}return t&&"zone"in t&&(this.zone=t.zone),this.zone||(this.zone=ICAL.Timezone.localTimezone),this._cachedUnixTime=null,this},dayOfWeek:function(){var t=(this.year<<9)+(this.month<<5)+this.day;if(t in ICAL.Time._dowCache)return ICAL.Time._dowCache[t];var e=this.day,n=this.month+(this.month<3?12:0),r=this.year-(this.month<3?1:0),i=e+r+ICAL.helpers.trunc(26*(n+1)/10)+ICAL.helpers.trunc(r/4);return i+=6*ICAL.helpers.trunc(r/100)+ICAL.helpers.trunc(r/400),i=(i+6)%7+1,ICAL.Time._dowCache[t]=i,i},dayOfYear:function(){var t=ICAL.Time.isLeapYear(this.year)?1:0;return ICAL.Time.daysInYearPassedMonth[t][this.month-1]+this.day},startOfWeek:function(t){var e=t||ICAL.Time.SUNDAY,n=this.clone();return n.day-=(this.dayOfWeek()+7-e)%7,n.isDate=!0,n.hour=0,n.minute=0,n.second=0,n},endOfWeek:function(t){var e=t||ICAL.Time.SUNDAY,n=this.clone();return n.day+=(7-this.dayOfWeek()+e-ICAL.Time.SUNDAY)%7,n.isDate=!0,n.hour=0,n.minute=0,n.second=0,n},startOfMonth:function(){var t=this.clone();return t.day=1,t.isDate=!0,t.hour=0,t.minute=0,t.second=0,t},endOfMonth:function(){var t=this.clone();return t.day=ICAL.Time.daysInMonth(t.month,t.year),t.isDate=!0,t.hour=0,t.minute=0,t.second=0,t},startOfYear:function(){var t=this.clone();return t.day=1,t.month=1,t.isDate=!0,t.hour=0,t.minute=0,t.second=0,t},endOfYear:function(){var t=this.clone();return t.day=31,t.month=12,t.isDate=!0,t.hour=0,t.minute=0,t.second=0,t},startDoyWeek:function(t){var e=t||ICAL.Time.SUNDAY,n=this.dayOfWeek()-e;return n<0&&(n+=7),this.dayOfYear()-n},getDominicalLetter:function(){return ICAL.Time.getDominicalLetter(this.year)},nthWeekDay:function(t,e){var n,r=ICAL.Time.daysInMonth(this.month,this.year),i=e,a=0,s=this.clone();if(i>=0){s.day=1,0!=i&&i--,a=s.day;var o=t-s.dayOfWeek();o<0&&(o+=7),a+=o,a-=t,n=t}else s.day=r,i++,(n=s.dayOfWeek()-t)<0&&(n+=7),n=r-n;return n+=7*i,a+n},isNthWeekDay:function(t,e){var n=this.dayOfWeek();return 0===e&&n===t||this.nthWeekDay(t,e)===this.day},weekNumber:function(t){var e=(this.year<<12)+(this.month<<8)+(this.day<<3)+t;if(e in ICAL.Time._wnCache)return ICAL.Time._wnCache[e];var n,r=this.clone();r.isDate=!0;var i=this.year;12==r.month&&r.day>25?(n=ICAL.Time.weekOneStarts(i+1,t),r.compare(n)<0?n=ICAL.Time.weekOneStarts(i,t):i++):(n=ICAL.Time.weekOneStarts(i,t),r.compare(n)<0&&(n=ICAL.Time.weekOneStarts(--i,t)));var a=r.subtractDate(n).toSeconds()/86400,s=ICAL.helpers.trunc(a/7)+1;return ICAL.Time._wnCache[e]=s,s},addDuration:function(t){var e=t.isNegative?-1:1,n=this.second,r=this.minute,i=this.hour,a=this.day;n+=e*t.seconds,r+=e*t.minutes,i+=e*t.hours,a+=e*t.days,a+=7*e*t.weeks,this.second=n,this.minute=r,this.hour=i,this.day=a,this._cachedUnixTime=null},subtractDate:function(t){var e=this.toUnixTime()+this.utcOffset(),n=t.toUnixTime()+t.utcOffset();return ICAL.Duration.fromSeconds(e-n)},subtractDateTz:function(t){var e=this.toUnixTime(),n=t.toUnixTime();return ICAL.Duration.fromSeconds(e-n)},compare:function(t){var e=this.toUnixTime(),n=t.toUnixTime();return e>n?1:n>e?-1:0},compareDateOnlyTz:function(t,e){function n(t){return ICAL.Time._cmp_attr(r,i,t)}var r=this.convertToZone(e),i=t.convertToZone(e),a=0;return 0!=(a=n("year"))?a:0!=(a=n("month"))?a:a=n("day")},convertToZone:function(t){var e=this.clone(),n=this.zone.tzid==t.tzid;return this.isDate||n||ICAL.Timezone.convert_time(e,this.zone,t),e.zone=t,e},utcOffset:function(){return this.zone==ICAL.Timezone.localTimezone||this.zone==ICAL.Timezone.utcTimezone?0:this.zone.utcOffset(this)},toICALString:function(){var t=this.toString();return t.length>10?ICAL.design.icalendar.value["date-time"].toICAL(t):ICAL.design.icalendar.value.date.toICAL(t)},toString:function(){var t=this.year+"-"+ICAL.helpers.pad2(this.month)+"-"+ICAL.helpers.pad2(this.day);return this.isDate||(t+="T"+ICAL.helpers.pad2(this.hour)+":"+ICAL.helpers.pad2(this.minute)+":"+ICAL.helpers.pad2(this.second),this.zone===ICAL.Timezone.utcTimezone&&(t+="Z")),t},toJSDate:function(){return this.zone==ICAL.Timezone.localTimezone?this.isDate?new Date(this.year,this.month-1,this.day):new Date(this.year,this.month-1,this.day,this.hour,this.minute,this.second,0):new Date(1e3*this.toUnixTime())},_normalize:function(){return this._time.isDate,this._time.isDate&&(this._time.hour=0,this._time.minute=0,this._time.second=0),this.adjust(0,0,0,0),this},adjust:function(t,e,n,r,i){var a,s,o,u,h,c,l,d=0,f=0,m=i||this._time;if(m.isDate||(o=m.second+r,m.second=o%60,a=ICAL.helpers.trunc(o/60),m.second<0&&(m.second+=60,a--),u=m.minute+n+a,m.minute=u%60,s=ICAL.helpers.trunc(u/60),m.minute<0&&(m.minute+=60,s--),h=m.hour+e+s,m.hour=h%24,d=ICAL.helpers.trunc(h/24),m.hour<0&&(m.hour+=24,d--)),m.month>12?f=ICAL.helpers.trunc((m.month-1)/12):m.month<1&&(f=ICAL.helpers.trunc(m.month/12)-1),m.year+=f,m.month-=12*f,(c=m.day+t+d)>0)for(;l=ICAL.Time.daysInMonth(m.month,m.year),!(c<=l);)++m.month>12&&(m.year++,m.month=1),c-=l;else for(;c<=0;)1==m.month?(m.year--,m.month=12):m.month--,c+=ICAL.Time.daysInMonth(m.month,m.year);return m.day=c,this._cachedUnixTime=null,this},fromUnixTime:function(t){this.zone=ICAL.Timezone.utcTimezone;var e=ICAL.Time.epochTime.clone();e.adjust(0,0,0,t),this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=Math.floor(e.second),this._cachedUnixTime=null},toUnixTime:function(){if(null!==this._cachedUnixTime)return this._cachedUnixTime;var t=this.utcOffset(),e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second-t);return this._cachedUnixTime=e/1e3,this._cachedUnixTime},toJSON:function(){for(var t,e=["year","month","day","hour","minute","second","isDate"],n=Object.create(null),r=0,i=e.length;r12?r:(r=n[t],2==t&&(r+=ICAL.Time.isLeapYear(e)),r)},ICAL.Time.isLeapYear=function(t){return t<=1752?t%4==0:t%4==0&&t%100!=0||t%400==0},ICAL.Time.fromDayOfYear=function(t,e){var n=e,r=t,i=new ICAL.Time;i.auto_normalize=!1;var a=ICAL.Time.isLeapYear(n)?1:0;if(r<1)return n--,a=ICAL.Time.isLeapYear(n)?1:0,r+=ICAL.Time.daysInYearPassedMonth[a][12],ICAL.Time.fromDayOfYear(r,n);if(r>ICAL.Time.daysInYearPassedMonth[a][12])return a=ICAL.Time.isLeapYear(n)?1:0,r-=ICAL.Time.daysInYearPassedMonth[a][12],n++,ICAL.Time.fromDayOfYear(r,n);i.year=n,i.isDate=!0;for(var s=11;s>=0;s--)if(r>ICAL.Time.daysInYearPassedMonth[a][s]){i.month=s+1,i.day=r-ICAL.Time.daysInYearPassedMonth[a][s];break}return i.auto_normalize=!0,i},ICAL.Time.fromStringv2=function(t){return new ICAL.Time({year:parseInt(t.substr(0,4),10),month:parseInt(t.substr(5,2),10),day:parseInt(t.substr(8,2),10),isDate:!0})},ICAL.Time.fromDateString=function(t){return new ICAL.Time({year:ICAL.helpers.strictParseInt(t.substr(0,4)),month:ICAL.helpers.strictParseInt(t.substr(5,2)),day:ICAL.helpers.strictParseInt(t.substr(8,2)),isDate:!0})},ICAL.Time.fromDateTimeString=function(t,e){if(t.length<19)throw new Error('invalid date-time value: "'+t+'"');var n;return t[19]&&"Z"===t[19]?n="Z":e&&(n=e.getParameter("tzid")),new ICAL.Time({year:ICAL.helpers.strictParseInt(t.substr(0,4)),month:ICAL.helpers.strictParseInt(t.substr(5,2)),day:ICAL.helpers.strictParseInt(t.substr(8,2)),hour:ICAL.helpers.strictParseInt(t.substr(11,2)),minute:ICAL.helpers.strictParseInt(t.substr(14,2)),second:ICAL.helpers.strictParseInt(t.substr(17,2)),timezone:n})},ICAL.Time.fromString=function(t){return t.length>10?ICAL.Time.fromDateTimeString(t):ICAL.Time.fromDateString(t)},ICAL.Time.fromJSDate=function(t,e){return(new ICAL.Time).fromJSDate(t,e)},ICAL.Time.fromData=function(t,e){return(new ICAL.Time).fromData(t,e)},ICAL.Time.now=function(){return ICAL.Time.fromJSDate(new Date,!1)},ICAL.Time.weekOneStarts=function(t,e){var n=ICAL.Time.fromData({year:t,month:1,day:1,isDate:!0}),r=n.dayOfWeek(),i=e||ICAL.Time.DEFAULT_WEEK_START;return r>ICAL.Time.THURSDAY&&(n.day+=7),i>ICAL.Time.THURSDAY&&(n.day-=7),n.day-=r-i,n},ICAL.Time.getDominicalLetter=function(t){var e=(t+(t/4|0)+(t/400|0)-(t/100|0)-1)%7;return ICAL.Time.isLeapYear(t)?"GFEDCBA"[(e+6)%7]+"GFEDCBA"[e]:"GFEDCBA"[e]},ICAL.Time.epochTime=ICAL.Time.fromData({year:1970,month:1,day:1,hour:0,minute:0,second:0,isDate:!1,timezone:"Z"}),ICAL.Time._cmp_attr=function(t,e,n){return t[n]>e[n]?1:t[n]4?d?n(u,1,2):n(u,3,2):null,second:4==c?n(u,2,2):6==c?n(u,4,2):8==c?n(u,6,2):null};return o="Z"==o?ICAL.Timezone.utcTimezone:o&&":"==o[3]?ICAL.UtcOffset.fromString(o):null,new ICAL.VCardTime(f,o,e)},function(){function t(t,e,n,r){var i=r;if("+"===r[0]&&(i=r.substr(1)),i=ICAL.helpers.strictParseInt(i),void 0!==e&&r '+e);if(void 0!==n&&r>n)throw new Error(t+': invalid value "'+r+'" must be < '+e);return i}var e={SU:ICAL.Time.SUNDAY,MO:ICAL.Time.MONDAY,TU:ICAL.Time.TUESDAY,WE:ICAL.Time.WEDNESDAY,TH:ICAL.Time.THURSDAY,FR:ICAL.Time.FRIDAY,SA:ICAL.Time.SATURDAY},n={};for(var r in e)e.hasOwnProperty(r)&&(n[e[r]]=r);ICAL.Recur=function(t){this.wrappedJSObject=this,this.parts={},t&&"object"==typeof t&&this.fromData(t)},ICAL.Recur.prototype={parts:null,interval:1,wkst:ICAL.Time.MONDAY,until:null,count:null,freq:null,icalclass:"icalrecur",icaltype:"recur",iterator:function(t){return new ICAL.RecurIterator({rule:this,dtstart:t})},clone:function(){return new ICAL.Recur(this.toJSON())},isFinite:function(){return!(!this.count&&!this.until)},isByCount:function(){return!(!this.count||this.until)},addComponent:function(t,e){var n=t.toUpperCase();n in this.parts?this.parts[n].push(e):this.parts[n]=[e]},setComponent:function(t,e){this.parts[t.toUpperCase()]=e.slice()},getComponent:function(t){var e=t.toUpperCase();return e in this.parts?this.parts[e].slice():[]},getNextOccurrence:function(t,e){var n,r=this.iterator(t);do{n=r.next()}while(n&&n.compare(e)<=0);return n&&e.zone&&(n.zone=e.zone),n},fromData:function(t){for(var e in t){var n=e.toUpperCase();n in u?Array.isArray(t[e])?this.parts[n]=t[e]:this.parts[n]=[t[e]]:this[e]=t[e]}this.interval&&"number"!=typeof this.interval&&o.INTERVAL(this.interval,this),this.wkst&&"number"!=typeof this.wkst&&(this.wkst=ICAL.Recur.icalDayToNumericDay(this.wkst)),!this.until||this.until instanceof ICAL.Time||(this.until=ICAL.Time.fromString(this.until))},toJSON:function(){var t=Object.create(null);t.freq=this.freq,this.count&&(t.count=this.count),this.interval>1&&(t.interval=this.interval);for(var e in this.parts)if(this.parts.hasOwnProperty(e)){var n=this.parts[e];Array.isArray(n)&&1==n.length?t[e.toLowerCase()]=n[0]:t[e.toLowerCase()]=ICAL.helpers.clone(this.parts[e])}return this.until&&(t.until=this.until.toString()),"wkst"in this&&this.wkst!==ICAL.Time.DEFAULT_WEEK_START&&(t.wkst=ICAL.Recur.numericDayToIcalDay(this.wkst)),t},toString:function(){var t="FREQ="+this.freq;this.count&&(t+=";COUNT="+this.count),this.interval>1&&(t+=";INTERVAL="+this.interval);for(var e in this.parts)this.parts.hasOwnProperty(e)&&(t+=";"+e+"="+this.parts[e]);return this.until&&(t+=";UNTIL="+this.until.toICALString()),"wkst"in this&&this.wkst!==ICAL.Time.DEFAULT_WEEK_START&&(t+=";WKST="+ICAL.Recur.numericDayToIcalDay(this.wkst)),t}},ICAL.Recur.icalDayToNumericDay=function(t){return e[t]},ICAL.Recur.numericDayToIcalDay=function(t){return n[t]};var i=/^(SU|MO|TU|WE|TH|FR|SA)$/,a=/^([+-])?(5[0-3]|[1-4][0-9]|[1-9])?(SU|MO|TU|WE|TH|FR|SA)$/,s=["SECONDLY","MINUTELY","HOURLY","DAILY","WEEKLY","MONTHLY","YEARLY"],o={FREQ:function(t,e,n){if(-1===s.indexOf(t))throw new Error('invalid frequency "'+t+'" expected: "'+s.join(", ")+'"');e.freq=t},COUNT:function(t,e,n){e.count=ICAL.helpers.strictParseInt(t)},INTERVAL:function(t,e,n){e.interval=ICAL.helpers.strictParseInt(t),e.interval<1&&(e.interval=1)},UNTIL:function(t,e,n){t.length>10?e.until=ICAL.design.icalendar.value["date-time"].fromICAL(t):e.until=ICAL.design.icalendar.value.date.fromICAL(t),n||(e.until=ICAL.Time.fromString(e.until))},WKST:function(t,e,n){if(!i.test(t))throw new Error('invalid WKST value "'+t+'"');e.wkst=ICAL.Recur.icalDayToNumericDay(t)}},u={BYSECOND:t.bind(this,"BYSECOND",0,60),BYMINUTE:t.bind(this,"BYMINUTE",0,59),BYHOUR:t.bind(this,"BYHOUR",0,23),BYDAY:function(t){if(a.test(t))return t;throw new Error('invalid BYDAY value "'+t+'"')},BYMONTHDAY:t.bind(this,"BYMONTHDAY",-31,31),BYYEARDAY:t.bind(this,"BYYEARDAY",-366,366),BYWEEKNO:t.bind(this,"BYWEEKNO",-53,53),BYMONTH:t.bind(this,"BYMONTH",0,12),BYSETPOS:t.bind(this,"BYSETPOS",-366,366)};ICAL.Recur.fromString=function(t){var e=ICAL.Recur._stringToData(t,!1);return new ICAL.Recur(e)},ICAL.Recur.fromData=function(t){return new ICAL.Recur(t)},ICAL.Recur._stringToData=function(t,e){for(var n=Object.create(null),r=t.split(";"),i=r.length,a=0;a=0||n<0)&&(this.last.day+=n)}else{var r=ICAL.Recur.numericDayToIcalDay(this.dtstart.dayOfWeek());t.BYDAY=[r]}if("YEARLY"==this.rule.freq){for(;this.expand_year_days(this.last.year),!(this.days.length>0);)this.increment_year(this.rule.interval);this._nextByYearDay()}if("MONTHLY"==this.rule.freq&&this.has_by_data("BYDAY")){var i=null,a=this.last.clone(),s=ICAL.Time.daysInMonth(this.last.month,this.last.year);for(var o in this.by_data.BYDAY)if(this.by_data.BYDAY.hasOwnProperty(o)){this.last=a.clone();var u=this.ruleDayOfWeek(this.by_data.BYDAY[o]),e=u[0],h=u[1],c=this.last.nthWeekDay(h,e);if(e>=6||e<=-6)throw new Error("Malformed values in BYDAY part");if(c>s||c<=0){if(i&&i.month==a.month)continue;for(;c>s||c<=0;)this.increment_month(),s=ICAL.Time.daysInMonth(this.last.month,this.last.year),c=this.last.nthWeekDay(h,e)}this.last.day=c,(!i||this.last.compare(i)<0)&&(i=this.last.clone())}if(this.last=i.clone(),this.has_by_data("BYMONTHDAY")&&this._byDayAndMonthDay(!0),this.last.day>s||0==this.last.day)throw new Error("Malformed values in BYDAY part")}else if(this.has_by_data("BYMONTHDAY")&&this.last.day<0){s=ICAL.Time.daysInMonth(this.last.month,this.last.year);this.last.day=s+this.last.day+1}},next:function(){var t=this.last?this.last.clone():null;if(this.rule.count&&this.occurrence_number>=this.rule.count||this.rule.until&&this.last.compare(this.rule.until)>0)return this.completed=!0,null;if(0==this.occurrence_number&&this.last.compare(this.dtstart)>=0)return this.occurrence_number++,this.last;var e;do{switch(e=1,this.rule.freq){case"SECONDLY":this.next_second();break;case"MINUTELY":this.next_minute();break;case"HOURLY":this.next_hour();break;case"DAILY":this.next_day();break;case"WEEKLY":this.next_week();break;case"MONTHLY":e=this.next_month();break;case"YEARLY":this.next_year();break;default:return null}}while(!this.check_contracting_rules()||this.last.compare(this.dtstart)<0||!e);if(0==this.last.compare(t))throw new Error("Same occurrence found twice, protecting you from death by recursion");return this.rule.until&&this.last.compare(this.rule.until)>0?(this.completed=!0,null):(this.occurrence_number++,this.last)},next_second:function(){return this.next_generic("BYSECOND","SECONDLY","second","minute")},increment_second:function(t){return this.increment_generic(t,"second",60,"minute")},next_minute:function(){return this.next_generic("BYMINUTE","MINUTELY","minute","hour","next_second")},increment_minute:function(t){return this.increment_generic(t,"minute",60,"hour")},next_hour:function(){return this.next_generic("BYHOUR","HOURLY","hour","monthday","next_minute")},increment_hour:function(t){this.increment_generic(t,"hour",24,"monthday")},next_day:function(){this.by_data;var t="DAILY"==this.rule.freq;return 0==this.next_hour()?0:(t?this.increment_monthday(this.rule.interval):this.increment_monthday(1),0)},next_week:function(){var t=0;if(0==this.next_weekday_by_week())return t;if(this.has_by_data("BYWEEKNO")){++this.by_indices.BYWEEKNO;this.by_indices.BYWEEKNO==this.by_data.BYWEEKNO.length&&(this.by_indices.BYWEEKNO=0,t=1),this.last.month=1,this.last.day=1;var e=this.by_data.BYWEEKNO[this.by_indices.BYWEEKNO];this.last.day+=7*e,t&&this.increment_year(1)}else this.increment_monthday(7*this.rule.interval);return t},normalizeByMonthDayRules:function(t,e,n){for(var r,i=ICAL.Time.daysInMonth(e,t),a=[],s=0,o=n.length;si)){if(r<0)r=i+(r+1);else if(0===r)continue;-1===a.indexOf(r)&&a.push(r)}return a.sort(function(t,e){return t-e})},_byDayAndMonthDay:function(t){function e(){for(s=ICAL.Time.daysInMonth(l.last.month,l.last.year),r=l.normalizeByMonthDayRules(l.last.year,l.last.month,l.by_data.BYMONTHDAY),a=r.length;r[u]<=d&&(!t||r[u]!=d)&&us)n();else{var m=r[u++];if(m>=i){d=m;for(var p=0;pe&&(this.last.day=1,this.increment_month(),this.is_day_in_byday(this.last)?this.has_by_data("BYSETPOS")&&!this.check_set_position(1)||(t=1):t=0)}else if(this.has_by_data("BYMONTHDAY")){++this.by_indices.BYMONTHDAY>=this.by_data.BYMONTHDAY.length&&(this.by_indices.BYMONTHDAY=0,this.increment_month());e=ICAL.Time.daysInMonth(this.last.month,this.last.year);(a=this.by_data.BYMONTHDAY[this.by_indices.BYMONTHDAY])<0&&(a=e+a+1),a>e?(this.last.day=1,t=this.is_day_in_byday(this.last)):this.last.day=a}else{this.increment_month();e=ICAL.Time.daysInMonth(this.last.month,this.last.year);this.by_data.BYMONTHDAY[0]>e?t=0:this.last.day=this.by_data.BYMONTHDAY[0]}return t},next_weekday_by_week:function(){var t=0;if(0==this.next_hour())return t;if(!this.has_by_data("BYDAY"))return 1;for(;;){var e=new ICAL.Time;++this.by_indices.BYDAY==Object.keys(this.by_data.BYDAY).length&&(this.by_indices.BYDAY=0,t=1);var n=this.by_data.BYDAY[this.by_indices.BYDAY],r=this.ruleDayOfWeek(n)[1];(r-=this.rule.wkst)<0&&(r+=7),e.year=this.last.year,e.month=this.last.month,e.day=this.last.day;var i=e.startDoyWeek(this.rule.wkst);if(!(r+i<1)||t){var a=ICAL.Time.fromDayOfYear(i+r,this.last.year);return this.last.year=a.year,this.last.month=a.month,this.last.day=a.day,t}}},next_year:function(){if(0==this.next_hour())return 0;if(++this.days_index==this.days.length){this.days_index=0;do{this.increment_year(this.rule.interval),this.expand_year_days(this.last.year)}while(0==this.days.length)}return this._nextByYearDay(),1},_nextByYearDay:function(){var t=this.days[this.days_index],e=this.last.year;t<1&&(t+=1,e+=1);var n=ICAL.Time.fromDayOfYear(t,e);this.last.day=n.day,this.last.month=n.month},ruleDayOfWeek:function(t){var e=t.match(/([+-]?[0-9])?(MO|TU|WE|TH|FR|SA|SU)/);if(e){var n=parseInt(e[1]||0,10);return t=ICAL.Recur.icalDayToNumericDay(e[2]),[n,t]}return[0,0]},next_generic:function(t,e,n,r,i){var a=t in this.by_data,s=this.rule.freq==e,o=0;if(i&&0==this[i]())return o;if(a){++this.by_indices[t];var u=this.by_data[t];this.by_indices[t]==u.length&&(this.by_indices[t]=0,o=1),this.last[n]=u[this.by_indices[t]]}else s&&this["increment_"+n](this.rule.interval);return a&&o&&s&&this["increment_"+r](1),o},increment_monthday:function(t){for(var e=0;en&&(this.last.day-=n,this.increment_month())}},increment_month:function(){if(this.last.day=1,this.has_by_data("BYMONTH"))++this.by_indices.BYMONTH==this.by_data.BYMONTH.length&&(this.by_indices.BYMONTH=0,this.increment_year(1)),this.last.month=this.by_data.BYMONTH[this.by_indices.BYMONTH];else{"MONTHLY"==this.rule.freq?this.last.month+=this.rule.interval:this.last.month++,this.last.month--;var t=ICAL.helpers.trunc(this.last.month/12);this.last.month%=12,this.last.month++,0!=t&&this.increment_year(t)}},increment_year:function(t){this.last.year+=t},increment_generic:function(t,e,n,r){this.last[e]+=t;var i=ICAL.helpers.trunc(this.last[e]/n);this.last[e]%=n,0!=i&&this["increment_"+r](i)},has_by_data:function(t){return t in this.rule.parts},expand_year_days:function(t){var e=new ICAL.Time;this.days=[];var n={},r=["BYDAY","BYWEEKNO","BYMONTHDAY","BYMONTH","BYYEARDAY"];for(var i in r)if(r.hasOwnProperty(i)){var a=r[i];a in this.rule.parts&&(n[a]=this.rule.parts[a])}if("BYMONTH"in n&&"BYWEEKNO"in n){var s=1,o={};e.year=t,e.isDate=!0;for(var u=0;u0?(S=z+7*(N-1))<=I&&this.days.push(v+S):(S=B+7*(N+1))>0&&this.days.push(v+S)}}this.days.sort(function(t,e){return t-e})}else if(2==d&&"BYDAY"in n&&"BYMONTHDAY"in n){j=this.expand_by_day(t);for(var P in j)if(j.hasOwnProperty(P)){var b=j[P],M=ICAL.Time.fromDayOfYear(b,t);this.by_data.BYMONTHDAY.indexOf(M.day)>=0&&this.days.push(b)}}else if(3==d&&"BYDAY"in n&&"BYMONTHDAY"in n&&"BYMONTH"in n){j=this.expand_by_day(t);for(var P in j)if(j.hasOwnProperty(P)){var b=j[P],M=ICAL.Time.fromDayOfYear(b,t);this.by_data.BYMONTH.indexOf(M.month)>=0&&this.by_data.BYMONTHDAY.indexOf(M.day)>=0&&this.days.push(b)}}else if(2==d&&"BYDAY"in n&&"BYWEEKNO"in n){var j=this.expand_by_day(t);for(var P in j)if(j.hasOwnProperty(P)){var b=j[P],k=(M=ICAL.Time.fromDayOfYear(b,t)).weekNumber(this.rule.wkst);this.by_data.BYWEEKNO.indexOf(k)&&this.days.push(b)}}else 3==d&&"BYDAY"in n&&"BYWEEKNO"in n&&"BYMONTHDAY"in n||(this.days=1==d&&"BYYEARDAY"in n?this.days.concat(this.by_data.BYYEARDAY):[]);return 0},expand_by_day:function(t){var e=[],n=this.last.clone();n.year=t,n.month=1,n.day=1,n.isDate=!0;var r=n.dayOfWeek();n.month=12,n.day=31,n.isDate=!0;var i=n.dayOfWeek(),a=n.dayOfYear();for(var s in this.by_data.BYDAY)if(this.by_data.BYDAY.hasOwnProperty(s)){var o=this.by_data.BYDAY[s],u=this.ruleDayOfWeek(o),h=u[0],c=u[1];if(0==h)for(var l=(c+7-r)%7+1;l<=a;l+=7)e.push(l);else if(h>0){var d;d=c>=r?c-r+1:c-r+8,e.push(d+7*(h-1))}else{var f;h=-h,f=c<=i?a-i+c:a-i+c-7,e.push(f-7*(h-1))}}return e},is_day_in_byday:function(t){for(var e in this.by_data.BYDAY)if(this.by_data.BYDAY.hasOwnProperty(e)){var n=this.by_data.BYDAY[e],r=this.ruleDayOfWeek(n),i=r[0],a=r[1],s=t.dayOfWeek();if(0==i&&a==s||t.nthWeekDay(a,i)==t.day)return 1}return 0},check_set_position:function(t){return!!this.has_by_data("BYSETPOS")&&-1!==this.by_data.BYSETPOS.indexOf(t)},sort_byday_rules:function(t,e){for(var n=0;na){var s=t[n];t[n]=t[r],t[r]=s}}},check_contract_restriction:function(e,n){var r=t._indexMap[e],i=t._expandMap[this.rule.freq][r],a=!1;if(e in this.by_data&&i==t.CONTRACT){var s=this.by_data[e];for(var o in s)if(s.hasOwnProperty(o)&&s[o]==n){a=!0;break}}else a=!0;return a},check_contracting_rules:function(){var t=this.last.dayOfWeek(),e=this.last.weekNumber(this.rule.wkst),n=this.last.dayOfYear();return this.check_contract_restriction("BYSECOND",this.last.second)&&this.check_contract_restriction("BYMINUTE",this.last.minute)&&this.check_contract_restriction("BYHOUR",this.last.hour)&&this.check_contract_restriction("BYDAY",ICAL.Recur.numericDayToIcalDay(t))&&this.check_contract_restriction("BYWEEKNO",e)&&this.check_contract_restriction("BYMONTHDAY",this.last.day)&&this.check_contract_restriction("BYMONTH",this.last.month)&&this.check_contract_restriction("BYYEARDAY",n)},setup_defaults:function(e,n,r){var i=t._indexMap[e];return t._expandMap[this.rule.freq][i]!=t.CONTRACT&&(e in this.by_data||(this.by_data[e]=[r]),this.rule.freq!=n)?this.by_data[e][0]:r},toJSON:function(){var t=Object.create(null);return t.initialized=this.initialized,t.rule=this.rule.toJSON(),t.dtstart=this.dtstart.toJSON(),t.by_data=this.by_data,t.days=this.days,t.last=this.last.toJSON(),t.by_indices=this.by_indices,t.occurrence_number=this.occurrence_number,t}},t._indexMap={BYSECOND:0,BYMINUTE:1,BYHOUR:2,BYDAY:3,BYMONTHDAY:4,BYYEARDAY:5,BYWEEKNO:6,BYMONTH:7,BYSETPOS:8},t._expandMap={SECONDLY:[1,1,1,1,1,1,1,1],MINUTELY:[2,1,1,1,1,1,1,1],HOURLY:[2,2,1,1,1,1,1,1],DAILY:[2,2,2,1,1,1,1,1],WEEKLY:[2,2,2,2,3,3,1,1],MONTHLY:[2,2,2,2,2,3,3,1],YEARLY:[2,2,2,2,2,2,2,2]},t.UNKNOWN=0,t.CONTRACT=1,t.EXPAND=2,t.ILLEGAL=3,t}(),ICAL.RecurExpansion=function(){function t(t){return ICAL.helpers.formatClassType(t,ICAL.Time)}function e(t,e){return t.compare(e)}function n(t){return t.hasProperty("rdate")||t.hasProperty("rrule")||t.hasProperty("recurrence-id")}function r(t){this.ruleDates=[],this.exDates=[],this.fromData(t)}return r.prototype={complete:!1,ruleIterators:null,ruleDates:null,exDates:null,ruleDateInc:0,exDateInc:0,exDate:null,ruleDate:null,dtstart:null,last:null,fromData:function(e){var n=ICAL.helpers.formatClassType(e.dtstart,ICAL.Time);if(!n)throw new Error(".dtstart (ICAL.Time) must be given");if(this.dtstart=n,e.component)this._init(e.component);else{if(this.last=t(e.last)||n.clone(),!e.ruleIterators)throw new Error(".ruleIterators or .component must be given");this.ruleIterators=e.ruleIterators.map(function(t){return ICAL.helpers.formatClassType(t,ICAL.RecurIterator)}),this.ruleDateInc=e.ruleDateInc,this.exDateInc=e.exDateInc,e.ruleDates&&(this.ruleDates=e.ruleDates.map(t),this.ruleDate=this.ruleDates[this.ruleDateInc]),e.exDates&&(this.exDates=e.exDates.map(t),this.exDate=this.exDates[this.exDateInc]),void 0!==e.complete&&(this.complete=e.complete)}},next:function(){for(var t,e,n,r=0;;){if(r++>500)throw new Error("max tries have occured, rule may be impossible to forfill.");if(e=this.ruleDate,t=this._nextRecurrenceIter(this.last),!e&&!t){this.complete=!0;break}if((!e||t&&e.compare(t.last)>0)&&(e=t.last.clone(),t.next()),this.ruleDate===e&&this._nextRuleDay(),this.last=e,!this.exDate||((n=this.exDate.compare(this.last))<0&&this._nextExDay(),0!==n))return this.last;this._nextExDay()}},toJSON:function(){function t(t){return t.toJSON()}var e=Object.create(null);return e.ruleIterators=this.ruleIterators.map(t),this.ruleDates&&(e.ruleDates=this.ruleDates.map(t)),this.exDates&&(e.exDates=this.exDates.map(t)),e.ruleDateInc=this.ruleDateInc,e.exDateInc=this.exDateInc,e.last=this.last.toJSON(),e.dtstart=this.dtstart.toJSON(),e.complete=this.complete,e},_extractDates:function(t,n){for(var r,i=[],a=t.getAllProperties(n),s=a.length,o=0;o0)&&(r=e);return r}},r}(),ICAL.Event=function(){function t(t,e){t instanceof ICAL.Component||(e=t,t=null),this.component=t||new ICAL.Component("vevent"),this._rangeExceptionCache=Object.create(null),this.exceptions=Object.create(null),this.rangeExceptions=[],e&&e.strictExceptions&&(this.strictExceptions=e.strictExceptions),e&&e.exceptions?e.exceptions.forEach(this.relateException,this):this.component.parent&&!this.isRecurrenceException()&&this.component.parent.getAllSubcomponents("vevent").forEach(function(t){t.hasProperty("recurrence-id")&&this.relateException(t)},this)}function e(t,e){return t[0]>e[0]?1:e[0]>t[0]?-1:0}return t.prototype={THISANDFUTURE:"THISANDFUTURE",exceptions:null,strictExceptions:!1,relateException:function(t){if(this.isRecurrenceException())throw new Error("cannot relate exception to exceptions");if(t instanceof ICAL.Component&&(t=new ICAL.Event(t)),this.strictExceptions&&t.uid!==this.uid)throw new Error("attempted to relate unrelated exception");var n=t.recurrenceId.toString();if(this.exceptions[n]=t,t.modifiesFuture()){var r=[t.recurrenceId.toUnixTime(),n],i=ICAL.helpers.binsearchInsert(this.rangeExceptions,r,e);this.rangeExceptions.splice(i,0,r)}},modifiesFuture:function(){return!!this.component.hasProperty("recurrence-id")&&this.component.getFirstProperty("recurrence-id").getParameter("range")===this.THISANDFUTURE},findRangeException:function(t){if(!this.rangeExceptions.length)return null;var n=t.toUnixTime(),r=ICAL.helpers.binsearchInsert(this.rangeExceptions,[n],e);if((r-=1)<0)return null;var i=this.rangeExceptions[r];return n0&&"\\"===t[n-1]))return n;n+=1}return-1},binsearchInsert:function(t,e,n){if(!t.length)return 0;for(var r,i,s=0,a=t.length-1;s<=a;)if(r=s+Math.floor((a-s)/2),(i=n(e,t[r]))<0)a=r-1;else{if(!(i>0))break;s=r+1}return i<0?r:i>0?r+1:r},dumpn:function(){ICAL.debug&&("undefined"!=typeof console&&"log"in console?ICAL.helpers.dumpn=function(t){console.log(t)}:ICAL.helpers.dumpn=function(t){dump(t+"\n")},ICAL.helpers.dumpn(arguments[0]))},clone:function(t,e){if(t&&"object"==typeof t){if(t instanceof Date)return new Date(t.getTime());if("clone"in t)return t.clone();if(Array.isArray(t)){for(var n=[],r=0;r11?t:t.substr(0,4)+t.substr(5,2)+t.substr(8,2)}},"date-time":{fromICAL:function(t){var e=t.substr(0,4)+"-"+t.substr(4,2)+"-"+t.substr(6,2)+"T"+t.substr(9,2)+":"+t.substr(11,2)+":"+t.substr(13,2);return t[15]&&"Z"===t[15]&&(e+="Z"),e},toICAL:function(t){if(t.length<19)return t;var e=t.substr(0,4)+t.substr(5,2)+t.substr(8,5)+t.substr(14,2)+t.substr(17,2);return t[19]&&"Z"===t[19]&&(e+="Z"),e},decorate:function(t,e){return ICAL.Time.fromDateTimeString(t,e)},undecorate:function(t){return t.toString()}},duration:{decorate:function(t){return ICAL.Duration.fromString(t)},undecorate:function(t){return t.toString()}},period:{fromICAL:function(t){var e=t.split("/");return e[0]=T["date-time"].fromICAL(e[0]),ICAL.Duration.isValueString(e[1])||(e[1]=T["date-time"].fromICAL(e[1])),e},toICAL:function(t){return t[0]=T["date-time"].toICAL(t[0]),ICAL.Duration.isValueString(t[1])||(t[1]=T["date-time"].toICAL(t[1])),t.join("/")},decorate:function(t,e){return ICAL.Period.fromJSON(t,e)},undecorate:function(t){return t.toJSON()}},recur:{fromICAL:function(t){return ICAL.Recur._stringToData(t,!0)},toICAL:function(t){var e="";for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)){var r=t[n];"until"==n?r=r.length>10?T["date-time"].toICAL(r):T.date.toICAL(r):"wkst"==n?"number"==typeof r&&(r=ICAL.Recur.numericDayToIcalDay(r)):Array.isArray(r)&&(r=r.join(",")),e+=n.toUpperCase()+"="+r+";"}return e.substr(0,e.length-1)},decorate:function(t){return ICAL.Recur.fromData(t)},undecorate:function(t){return t.toJSON()}},time:{fromICAL:function(t){if(t.length<6)return t;var e=t.substr(0,2)+":"+t.substr(2,2)+":"+t.substr(4,2);return"Z"===t[6]&&(e+="Z"),e},toICAL:function(t){if(t.length<8)return t;var e=t.substr(0,2)+t.substr(3,2)+t.substr(6,2);return"Z"===t[8]&&(e+="Z"),e}}}),_=ICAL.helpers.extend(A,{action:o,attach:{defaultType:"uri"},attendee:{defaultType:"cal-address"},calscale:o,class:o,comment:o,completed:d,contact:o,created:d,description:o,dtend:l,dtstamp:d,dtstart:l,due:l,duration:{defaultType:"duration"},exdate:{defaultType:"date-time",allowedTypes:["date-time","date"],multiValue:","},exrule:p,freebusy:{defaultType:"period",multiValue:","},geo:{defaultType:"float",structuredValue:";"},"last-modified":d,location:o,method:o,organizer:{defaultType:"cal-address"},"percent-complete":c,priority:c,prodid:o,"related-to":o,repeat:c,rdate:{defaultType:"date-time",allowedTypes:["date-time","date","period"],multiValue:",",detectType:function(t){return-1!==t.indexOf("/")?"period":-1===t.indexOf("T")?"date":"date-time"}},"recurrence-id":l,resources:u,"request-status":h,rrule:p,sequence:c,status:o,summary:o,transp:o,trigger:{defaultType:"duration",allowedTypes:["duration","date-time"]},tzoffsetfrom:m,tzoffsetto:m,tzurl:f,tzid:o,tzname:o}),L=ICAL.helpers.extend(C,{text:t(s,a),uri:t(s,a),date:{decorate:function(t){return ICAL.VCardTime.fromDateAndOrTimeString(t,"date")},undecorate:function(t){return t.toString()},fromICAL:function(t){return 8==t.length?T.date.fromICAL(t):"-"==t[0]&&6==t.length?t.substr(0,4)+"-"+t.substr(4):t},toICAL:function(t){return 10==t.length?T.date.toICAL(t):"-"==t[0]&&7==t.length?t.substr(0,4)+t.substr(5):t}},time:{decorate:function(t){return ICAL.VCardTime.fromDateAndOrTimeString("T"+t,"time")},undecorate:function(t){return t.toString()},fromICAL:function(t){var e=L.time._splitZone(t,!0),n=e[0],r=e[1];return 6==r.length?r=r.substr(0,2)+":"+r.substr(2,2)+":"+r.substr(4,2):4==r.length&&"-"!=r[0]?r=r.substr(0,2)+":"+r.substr(2,2):5==r.length&&(r=r.substr(0,3)+":"+r.substr(3,2)),5!=n.length||"-"!=n[0]&&"+"!=n[0]||(n=n.substr(0,3)+":"+n.substr(3)),r+n},toICAL:function(t){var e=L.time._splitZone(t),n=e[0],r=e[1];return 8==r.length?r=r.substr(0,2)+r.substr(3,2)+r.substr(6,2):5==r.length&&"-"!=r[0]?r=r.substr(0,2)+r.substr(3,2):6==r.length&&(r=r.substr(0,3)+r.substr(4,2)),6!=n.length||"-"!=n[0]&&"+"!=n[0]||(n=n.substr(0,3)+n.substr(4)),r+n},_splitZone:function(t,e){var n,r,i=t.length-1,s=t.length-(e?5:6),a=t[s];return"Z"==t[i]?(n=t[i],r=t.substr(0,i)):t.length>6&&("-"==a||"+"==a)?(n=t.substr(s),r=t.substr(0,s)):(n="",r=t),[n,r]}},"date-time":{decorate:function(t){return ICAL.VCardTime.fromDateAndOrTimeString(t,"date-time")},undecorate:function(t){return t.toString()},fromICAL:function(t){return L["date-and-or-time"].fromICAL(t)},toICAL:function(t){return L["date-and-or-time"].toICAL(t)}},"date-and-or-time":{decorate:function(t){return ICAL.VCardTime.fromDateAndOrTimeString(t,"date-and-or-time")},undecorate:function(t){return t.toString()},fromICAL:function(t){var e=t.split("T");return(e[0]?L.date.fromICAL(e[0]):"")+(e[1]?"T"+L.time.fromICAL(e[1]):"")},toICAL:function(t){var e=t.split("T");return L.date.toICAL(e[0])+(e[1]?"T"+L.time.toICAL(e[1]):"")}},timestamp:T["date-time"],"language-tag":{matches:/^[a-zA-Z0-9-]+$/}}),v={type:{valueType:"text",multiValue:","},value:{values:["text","uri","date","time","date-time","date-and-or-time","timestamp","boolean","integer","float","utc-offset","language-tag"],allowXName:!0,allowIanaToken:!0}},g=ICAL.helpers.extend(A,{adr:{defaultType:"text",structuredValue:";",multiValue:","},anniversary:y,bday:y,caladruri:f,caluri:f,clientpidmap:h,email:o,fburl:f,fn:o,gender:h,geo:f,impp:f,key:f,kind:o,lang:{defaultType:"language-tag"},logo:f,member:f,n:{defaultType:"text",structuredValue:";",multiValue:","},nickname:u,note:o,org:{defaultType:"text",structuredValue:";"},photo:f,related:f,rev:{defaultType:"timestamp"},role:o,sound:f,source:f,tel:{defaultType:"uri",allowedTypes:["uri","text"]},title:o,tz:{defaultType:"text",allowedTypes:["text","utc-offset","uri"]},xml:o}),D=ICAL.helpers.extend(C,{binary:T.binary,date:L.date,"date-time":L["date-time"],"phone-number":{},uri:T.uri,text:T.text,time:T.time,vcard:T.text,"utc-offset":{toICAL:function(t){return t.substr(0,7)},fromICAL:function(t){return t.substr(0,7)},decorate:function(t){return ICAL.UtcOffset.fromString(t)},undecorate:function(t){return t.toString()}}}),b={type:{valueType:"text",multiValue:","},value:{values:["text","uri","date","date-time","phone-number","time","boolean","integer","float","utc-offset","vcard","binary"],allowXName:!0,allowIanaToken:!0}},Y=ICAL.helpers.extend(A,{fn:o,n:{defaultType:"text",structuredValue:";",multiValue:","},nickname:u,photo:{defaultType:"binary",allowedTypes:["binary","uri"]},bday:{defaultType:"date-time",allowedTypes:["date-time","date"],detectType:function(t){return-1===t.indexOf("T")?"date":"date-time"}},adr:{defaultType:"text",structuredValue:";",multiValue:","},label:o,tel:{defaultType:"phone-number"},email:o,mailer:o,tz:{defaultType:"utc-offset",allowedTypes:["utc-offset","text"]},geo:{defaultType:"float",structuredValue:";"},title:o,role:o,logo:{defaultType:"binary",allowedTypes:["binary","uri"]},agent:{defaultType:"vcard",allowedTypes:["vcard","text","uri"]},org:h,note:u,prodid:o,rev:{defaultType:"date-time",allowedTypes:["date-time","date"],detectType:function(t){return-1===t.indexOf("T")?"date":"date-time"}},"sort-string":o,sound:{defaultType:"binary",allowedTypes:["binary","uri"]},class:o,key:{defaultType:"binary",allowedTypes:["binary","text"]}}),O={value:T,param:I,property:_},S={value:L,param:v,property:g},E={value:D,param:b,property:Y},w={defaultSet:O,defaultType:"unknown",components:{vcard:S,vcard3:E,vevent:O,vtodo:O,vjournal:O,valarm:O,vtimezone:O,daylight:O,standard:O},icalendar:O,vcard:S,vcard3:E,getDesignSet:function(t){return t&&t in w.components?w.components[t]:w.defaultSet}};return w}(),ICAL.stringify=function(){"use strict";function t(n){"string"==typeof n[0]&&(n=[n]);for(var r=0,i=n.length,s="";r0&&("version"!==r[1][0][0]||"4.0"!==r[1][0][3])&&(c="vcard3"),i=i||n.getDesignSet(c);u1)throw new t("invalid ical body. component began but did not end");return r=null,1==i.length?i[0]:i}var n=/[^ \t]/,r=ICAL.design,i=ICAL.helpers;t.prototype=Error.prototype,e.property=function(t,n){var i={component:[[],[]],designSet:n||r.defaultSet};return e._handleContentLine(t,i),i.component[1][0]},e.component=function(t){return e(t)},e.ParserError=t,e._handleContentLine=function(n,i){var s,a,o,u,h=n.indexOf(":"),c=n.indexOf(";"),l={};-1!==c&&-1!==h&&c>h&&(c=-1);var d;if(-1!==c){if(o=n.substring(0,c).toLowerCase(),-1==(d=e._parseParameters(n.substring(c),0,i.designSet))[2])throw new t("Invalid parameters in '"+n+"'");if(l=d[0],s=d[1].length+d[2]+c,-1===(a=n.substring(s).indexOf(":")))throw new t("Missing parameter value in '"+n+"'");u=n.substring(s+a+1)}else{if(-1===h)throw new t('invalid line (no token ";" or ":") "'+n+'"');if(o=n.substring(0,h).toLowerCase(),u=n.substring(h+1),"begin"===o){var f=[u.toLowerCase(),[],[]];return 1===i.stack.length?i.component.push(f):i.component[2].push(f),i.stack.push(i.component),i.component=f,void(i.designSet||(i.designSet=r.getDesignSet(i.component[0])))}if("end"===o)return void(i.component=i.stack.pop())}var m,p,y=!1,A=!1;o in i.designSet.property&&("multiValue"in(p=i.designSet.property[o])&&(y=p.multiValue),"structuredValue"in p&&(A=p.structuredValue),u&&"detectType"in p&&(m=p.detectType(u))),m||(m="value"in l?l.value.toLowerCase():p?p.defaultType:"unknown"),delete l.value;var C;y&&A?C=[o,l,m,u=e._parseMultiValue(u,A,m,[],y,i.designSet,A)]:y?(C=[o,l,m],e._parseMultiValue(u,y,m,C,null,i.designSet,!1)):C=A?[o,l,m,u=e._parseMultiValue(u,A,m,[],null,i.designSet,A)]:[o,l,m,u=e._parseValue(u,m,i.designSet,!1)],"vcard"!==i.component[0]||0!==i.component[1].length||"version"===o&&"4.0"===u||(i.designSet=r.getDesignSet("vcard3")),i.component[1].push(C)},e._parseValue=function(t,e,n,r){return e in n.value&&"fromICAL"in n.value[e]?n.value[e].fromICAL(t,r):t},e._parseParameters=function(n,r,s){for(var a,o,u,h,c,l,d=r,f=0,m={},p=-1;!1!==f&&-1!==(f=i.unescapedIndexOf(n,"=",f+1));){if(0==(a=n.substr(d+1,f-d-1)).length)throw new t("Empty parameter name in '"+n+"'");if(h=(o=a.toLowerCase())in s.param&&s.param[o].valueType?s.param[o].valueType:"text",o in s.param&&(c=s.param[o].multiValue,s.param[o].multiValueSeparateDQuote&&(l=e._rfc6868Escape('"'+c+'"'))),'"'===n[f+1]){if(p=f+2,f=i.unescapedIndexOf(n,'"',p),c&&-1!=f)for(var y=!0;y;)n[f+1]==c&&'"'==n[f+2]?f=i.unescapedIndexOf(n,'"',f+3):y=!1;if(-1===f)throw new t('invalid line (no matching double quote) "'+n+'"');u=n.substr(p,f-p),-1===(d=i.unescapedIndexOf(n,";",f))&&(f=!1)}else{p=f+1;var A=i.unescapedIndexOf(n,";",p),C=i.unescapedIndexOf(n,":",p);-1!==C&&A>C?(A=C,f=!1):-1===A?(A=-1===C?n.length:C,f=!1):(d=A,f=A),u=n.substr(p,A-p)}if(u=e._rfc6868Escape(u),c){var I=l||c;m[o]=e._parseMultiValue(u,I,h,[],null,s)}else m[o]=e._parseValue(u,h,s)}return[m,u,p]},e._rfc6868Escape=function(t){return t.replace(/\^['n^]/g,function(t){return s[t]})};var s={"^'":'"',"^n":"\n","^^":"^"};return e._parseMultiValue=function(t,n,r,s,a,o,u){var h,c=0,l=0;if(0===n.length)return t;for(;-1!==(c=i.unescapedIndexOf(t,n,l));)h=t.substr(l,c-l),h=a?e._parseMultiValue(h,a,r,[],null,o,u):e._parseValue(h,r,o,u),s.push(h),l=c+n.length;return h=t.substr(l),h=a?e._parseMultiValue(h,a,r,[],null,o,u):e._parseValue(h,r,o,u),s.push(h),1==s.length?s[0]:s},e._eachLine=function(t,e){var r,i,s,a=t.length,o=t.search(n),u=o;do{s=(u=t.indexOf("\n",o)+1)>1&&"\r"===t[u-2]?2:1,0===u&&(u=a,s=0)," "===(i=t[o])||"\t"===i?r+=t.substr(o+1,u-o-(s+1)):(r&&e(null,r),r=t.substr(o,u-o-s)),o=u}while(u!==a);(r=r.trim()).length&&e(null,r)},e}(),ICAL.Component=function(){"use strict";function t(t,e){"string"==typeof t&&(t=[t,[],[]]),this.jCal=t,this.parent=e||null}var e=0;return t.prototype={_hydratedPropertyCount:0,_hydratedComponentCount:0,get name(){return this.jCal[e]},get _designSet(){return this.parent&&this.parent._designSet||ICAL.design.getDesignSet(this.name)},_hydrateComponent:function(e){if(this._components||(this._components=[],this._hydratedComponentCount=0),this._components[e])return this._components[e];var n=new t(this.jCal[2][e],this);return this._hydratedComponentCount++,this._components[e]=n},_hydrateProperty:function(t){if(this._properties||(this._properties=[],this._hydratedPropertyCount=0),this._properties[t])return this._properties[t];var e=new ICAL.Property(this.jCal[1][t],this);return this._hydratedPropertyCount++,this._properties[t]=e},getFirstSubcomponent:function(t){if(t){for(var n=0,r=this.jCal[2],i=r.length;n=0;a--)r&&s[a][e]!==r||this._removeObjectByIndex(t,i,a)},addSubcomponent:function(t){this._components||(this._components=[],this._hydratedComponentCount=0),t.parent&&t.parent.removeSubcomponent(t);var e=this.jCal[2].push(t.jCal);return this._components[e-1]=t,this._hydratedComponentCount++,t.parent=this,t},removeSubcomponent:function(t){var e=this._removeObject(2,"_components",t);return e&&this._hydratedComponentCount--,e},removeAllSubcomponents:function(t){var e=this._removeAllObjects(2,"_components",t);return this._hydratedComponentCount=0,e},addProperty:function(t){if(!(t instanceof ICAL.Property))throw new TypeError("must instance of ICAL.Property");this._properties||(this._properties=[],this._hydratedPropertyCount=0),t.parent&&t.parent.removeProperty(t);var e=this.jCal[1].push(t.jCal);return this._properties[e-1]=t,this._hydratedPropertyCount++,t.parent=this,t},addPropertyWithValue:function(t,e){var n=new ICAL.Property(t);return n.setValue(e),this.addProperty(n),n},updatePropertyWithValue:function(t,e){var n=this.getFirstProperty(t);return n?n.setValue(e):n=this.addPropertyWithValue(t,e),n},removeProperty:function(t){var e=this._removeObject(1,"_properties",t);return e&&this._hydratedPropertyCount--,e},removeAllProperties:function(t){var e=this._removeAllObjects(1,"_properties",t);return this._hydratedPropertyCount=0,e},toJSON:function(){return this.jCal},toString:function(){return ICAL.stringify.component(this.jCal,this._designSet)}},t.fromString=function(e){return new t(ICAL.parse.component(e))},t}(),ICAL.Property=function(){"use strict";function t(t,e){this._parent=e||null,"string"==typeof t?(this.jCal=[t,{},r.defaultType],this.jCal[n]=this.getDefaultType()):this.jCal=t,this._updateType()}var e=0,n=2,r=ICAL.design;return t.prototype={get type(){return this.jCal[n]},get name(){return this.jCal[e]},get parent(){return this._parent},set parent(t){var e=!this._parent||t&&t._designSet!=this._parent._designSet;return this._parent=t,this.type==r.defaultType&&e&&(this.jCal[n]=this.getDefaultType(),this._updateType()),t},get _designSet(){return this.parent?this.parent._designSet:r.defaultSet},_updateType:function(){var t=this._designSet;if(this.type in t.value){t.value[this.type];"decorate"in t.value[this.type]?this.isDecorated=!0:this.isDecorated=!1,this.name in t.property&&(this.isMultiValue="multiValue"in t.property[this.name],this.isStructuredValue="structuredValue"in t.property[this.name])}},_hydrateValue:function(t){return this._values&&this._values[t]?this._values[t]:this.jCal.length<=3+t?null:this.isDecorated?(this._values||(this._values=[]),this._values[t]=this._decorate(this.jCal[3+t])):this.jCal[3+t]},_decorate:function(t){return this._designSet.value[this.type].decorate(t,this)},_undecorate:function(t){return this._designSet.value[this.type].undecorate(t,this)},_setDecoratedValue:function(t,e){this._values||(this._values=[]),"object"==typeof t&&"icaltype"in t?(this.jCal[3+e]=this._undecorate(t),this._values[e]=t):(this.jCal[3+e]=t,this._values[e]=this._decorate(t))},getParameter:function(t){return t in this.jCal[1]?this.jCal[1][t]:void 0},setParameter:function(t,e){var n=t.toLowerCase();"string"==typeof e&&n in this._designSet.param&&"multiValue"in this._designSet.param[n]&&(e=[e]),this.jCal[1][t]=e},removeParameter:function(t){delete this.jCal[1][t]},getDefaultType:function(){var t=this.jCal[e],n=this._designSet;if(t in n.property){var i=n.property[t];if("defaultType"in i)return i.defaultType}return r.defaultType},resetType:function(t){this.removeAllValues(),this.jCal[n]=t,this._updateType()},getFirstValue:function(){return this._hydrateValue(0)},getValues:function(){var t=this.jCal.length-3;if(t<1)return[];for(var e=0,n=[];e0&&"object"==typeof t[0]&&"icaltype"in t[0]&&this.resetType(t[0].icaltype),this.isDecorated)for(;nn)-(n>e)},_normalize:function(){for(var t=this.toSeconds(),e=this.factor;t<-43200;)t+=97200;for(;t>50400;)t-=97200;this.fromSeconds(t),0==t&&(this.factor=e)},toICALString:function(){return ICAL.design.icalendar.value["utc-offset"].toICAL(this.toString())},toString:function(){return(1==this.factor?"+":"-")+ICAL.helpers.pad2(this.hours)+":"+ICAL.helpers.pad2(this.minutes)}},t.fromString=function(t){var e={};return e.factor="+"===t[0]?1:-1,e.hours=ICAL.helpers.strictParseInt(t.substr(1,2)),e.minutes=ICAL.helpers.strictParseInt(t.substr(4,2)),new ICAL.UtcOffset(e)},t.fromSeconds=function(e){var n=new t;return n.fromSeconds(e),n},t}(),ICAL.Binary=function(){function t(t){this.value=t}return t.prototype={icaltype:"binary",decodeValue:function(){return this._b64_decode(this.value)},setEncodedValue:function(t){this.value=this._b64_encode(t)},_b64_encode:function(t){var e,n,r,i,s,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,u=0,h="",c=[];if(!t)return t;do{e=(s=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>18&63,n=s>>12&63,r=s>>6&63,i=63&s,c[u++]=a.charAt(e)+a.charAt(n)+a.charAt(r)+a.charAt(i)}while(o>16&255,n=a>>8&255,r=255&a,c[h++]=64==i?String.fromCharCode(e):64==s?String.fromCharCode(e,n):String.fromCharCode(e,n,r)}while(un)-(e=0?r=n:i=-1,-1==i&&-1!=r)break;if((n+=i)<0)return 0;if(n>=this.changes.length)break}var a=this.changes[r];if(a.utcOffset-a.prevUtcOffset<0&&r>0){var o=ICAL.helpers.clone(a,!0);if(ICAL.Timezone.adjust_change(o,0,0,0,o.prevUtcOffset),ICAL.Timezone._compare_change_fn(e,o)<0){var u=this.changes[r-1];0!=a.is_daylight&&0==u.is_daylight&&(a=u)}}return a.utcOffset},_findNearbyChange:function(t){var e=ICAL.helpers.binsearchInsert(this.changes,t,ICAL.Timezone._compare_change_fn);return e>=this.changes.length?this.changes.length-1:e},_ensureCoverage:function(t){if(-1==ICAL.Timezone._minimumExpansionYear){var e=ICAL.Time.now();ICAL.Timezone._minimumExpansionYear=e.year}var n=t;if(nICAL.Timezone.MAX_YEAR&&(n=ICAL.Timezone.MAX_YEAR),!this.changes.length||this.expandedUntilYeare)&&l);)s.year=l.year,s.month=l.month,s.day=l.day,s.hour=l.hour,s.minute=l.minute,s.second=l.second,s.isDate=l.isDate,ICAL.Timezone.adjust_change(s,0,0,0,-s.prevUtcOffset),n.push(s)}}else(s=i()).year=a.year,s.month=a.month,s.day=a.day,s.hour=a.hour,s.minute=a.minute,s.second=a.second,ICAL.Timezone.adjust_change(s,0,0,0,-s.prevUtcOffset),n.push(s);return n},toString:function(){return this.tznames?this.tznames:this.tzid}},ICAL.Timezone._compare_change_fn=function(t,e){return t.yeare.year?1:t.monthe.month?1:t.daye.day?1:t.houre.hour?1:t.minutee.minute?1:t.seconde.second?1:0},ICAL.Timezone.convert_time=function(t,e,n){if(t.isDate||e.tzid==n.tzid||e==ICAL.Timezone.localTimezone||n==ICAL.Timezone.localTimezone)return t.zone=n,t;var r=e.utcOffset(t);return t.adjust(0,0,0,-r),r=n.utcOffset(t),t.adjust(0,0,0,r),null},ICAL.Timezone.fromData=function(t){return(new ICAL.Timezone).fromData(t)},ICAL.Timezone.utcTimezone=ICAL.Timezone.fromData({tzid:"UTC"}),ICAL.Timezone.localTimezone=ICAL.Timezone.fromData({tzid:"floating"}),ICAL.Timezone.adjust_change=function(t,e,n,r,i){return ICAL.Time.prototype.adjust.call(t,e,n,r,i,t)},ICAL.Timezone._minimumExpansionYear=-1,ICAL.Timezone.MAX_YEAR=2035,ICAL.Timezone.EXTRA_COVERAGE=5}(),ICAL.TimezoneService=function(){var t,e={reset:function(){t=Object.create(null);var e=ICAL.Timezone.utcTimezone;t.Z=e,t.UTC=e,t.GMT=e},has:function(e){return!!t[e]},get:function(e){return t[e]},register:function(e,n){if(e instanceof ICAL.Component&&"vtimezone"===e.name&&(e=(n=new ICAL.Timezone(e)).tzid),!(n instanceof ICAL.Timezone))throw new TypeError("timezone must be ICAL.Timezone or ICAL.Component");t[e]=n},remove:function(e){return delete t[e]}};return e.reset(),e}(),ICAL.Time=function(t,e){this.wrappedJSObject=this;var n=this._time=Object.create(null);n.year=0,n.month=1,n.day=1,n.hour=0,n.minute=0,n.second=0,n.isDate=!1,this.fromData(t,e)},ICAL.Time._dowCache={},ICAL.Time._wnCache={},ICAL.Time.prototype={icalclass:"icaltime",_cachedUnixTime:null,get icaltype(){return this.isDate?"date":"date-time"},zone:null,_pendingNormalization:!1,clone:function(){return new ICAL.Time(this._time,this.zone)},reset:function(){this.fromData(ICAL.Time.epochTime),this.zone=ICAL.Timezone.utcTimezone},resetTo:function(t,e,n,r,i,s,a){this.fromData({year:t,month:e,day:n,hour:r,minute:i,second:s,zone:a})},fromJSDate:function(t,e){return t?e?(this.zone=ICAL.Timezone.utcTimezone,this.year=t.getUTCFullYear(),this.month=t.getUTCMonth()+1,this.day=t.getUTCDate(),this.hour=t.getUTCHours(),this.minute=t.getUTCMinutes(),this.second=t.getUTCSeconds()):(this.zone=ICAL.Timezone.localTimezone,this.year=t.getFullYear(),this.month=t.getMonth()+1,this.day=t.getDate(),this.hour=t.getHours(),this.minute=t.getMinutes(),this.second=t.getSeconds()):this.reset(),this._cachedUnixTime=null,this},fromData:function(t,e){if(t)for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)){if("icaltype"===n)continue;this[n]=t[n]}if(e&&(this.zone=e),!t||"isDate"in t?t&&"isDate"in t&&(this.isDate=t.isDate):this.isDate=!("hour"in t),t&&"timezone"in t){var r=ICAL.TimezoneService.get(t.timezone);this.zone=r||ICAL.Timezone.localTimezone}return t&&"zone"in t&&(this.zone=t.zone),this.zone||(this.zone=ICAL.Timezone.localTimezone),this._cachedUnixTime=null,this},dayOfWeek:function(){var t=(this.year<<9)+(this.month<<5)+this.day;if(t in ICAL.Time._dowCache)return ICAL.Time._dowCache[t];var e=this.day,n=this.month+(this.month<3?12:0),r=this.year-(this.month<3?1:0),i=e+r+ICAL.helpers.trunc(26*(n+1)/10)+ICAL.helpers.trunc(r/4);return i+=6*ICAL.helpers.trunc(r/100)+ICAL.helpers.trunc(r/400),i=(i+6)%7+1,ICAL.Time._dowCache[t]=i,i},dayOfYear:function(){var t=ICAL.Time.isLeapYear(this.year)?1:0;return ICAL.Time.daysInYearPassedMonth[t][this.month-1]+this.day},startOfWeek:function(t){var e=t||ICAL.Time.SUNDAY,n=this.clone();return n.day-=(this.dayOfWeek()+7-e)%7,n.isDate=!0,n.hour=0,n.minute=0,n.second=0,n},endOfWeek:function(t){var e=t||ICAL.Time.SUNDAY,n=this.clone();return n.day+=(7-this.dayOfWeek()+e-ICAL.Time.SUNDAY)%7,n.isDate=!0,n.hour=0,n.minute=0,n.second=0,n},startOfMonth:function(){var t=this.clone();return t.day=1,t.isDate=!0,t.hour=0,t.minute=0,t.second=0,t},endOfMonth:function(){var t=this.clone();return t.day=ICAL.Time.daysInMonth(t.month,t.year),t.isDate=!0,t.hour=0,t.minute=0,t.second=0,t},startOfYear:function(){var t=this.clone();return t.day=1,t.month=1,t.isDate=!0,t.hour=0,t.minute=0,t.second=0,t},endOfYear:function(){var t=this.clone();return t.day=31,t.month=12,t.isDate=!0,t.hour=0,t.minute=0,t.second=0,t},startDoyWeek:function(t){var e=t||ICAL.Time.SUNDAY,n=this.dayOfWeek()-e;return n<0&&(n+=7),this.dayOfYear()-n},getDominicalLetter:function(){return ICAL.Time.getDominicalLetter(this.year)},nthWeekDay:function(t,e){var n,r=ICAL.Time.daysInMonth(this.month,this.year),i=e,s=0,a=this.clone();if(i>=0){a.day=1,0!=i&&i--,s=a.day;var o=t-a.dayOfWeek();o<0&&(o+=7),s+=o,s-=t,n=t}else a.day=r,i++,(n=a.dayOfWeek()-t)<0&&(n+=7),n=r-n;return n+=7*i,s+n},isNthWeekDay:function(t,e){var n=this.dayOfWeek();return 0===e&&n===t||this.nthWeekDay(t,e)===this.day},weekNumber:function(t){var e=(this.year<<12)+(this.month<<8)+(this.day<<3)+t;if(e in ICAL.Time._wnCache)return ICAL.Time._wnCache[e];var n,r=this.clone();r.isDate=!0;var i=this.year;12==r.month&&r.day>25?(n=ICAL.Time.weekOneStarts(i+1,t),r.compare(n)<0?n=ICAL.Time.weekOneStarts(i,t):i++):(n=ICAL.Time.weekOneStarts(i,t),r.compare(n)<0&&(n=ICAL.Time.weekOneStarts(--i,t)));var s=r.subtractDate(n).toSeconds()/86400,a=ICAL.helpers.trunc(s/7)+1;return ICAL.Time._wnCache[e]=a,a},addDuration:function(t){var e=t.isNegative?-1:1,n=this.second,r=this.minute,i=this.hour,s=this.day;n+=e*t.seconds,r+=e*t.minutes,i+=e*t.hours,s+=e*t.days,s+=7*e*t.weeks,this.second=n,this.minute=r,this.hour=i,this.day=s,this._cachedUnixTime=null},subtractDate:function(t){var e=this.toUnixTime()+this.utcOffset(),n=t.toUnixTime()+t.utcOffset();return ICAL.Duration.fromSeconds(e-n)},subtractDateTz:function(t){var e=this.toUnixTime(),n=t.toUnixTime();return ICAL.Duration.fromSeconds(e-n)},compare:function(t){var e=this.toUnixTime(),n=t.toUnixTime();return e>n?1:n>e?-1:0},compareDateOnlyTz:function(t,e){function n(t){return ICAL.Time._cmp_attr(r,i,t)}var r=this.convertToZone(e),i=t.convertToZone(e),s=0;return 0!=(s=n("year"))?s:0!=(s=n("month"))?s:s=n("day")},convertToZone:function(t){var e=this.clone(),n=this.zone.tzid==t.tzid;return this.isDate||n||ICAL.Timezone.convert_time(e,this.zone,t),e.zone=t,e},utcOffset:function(){return this.zone==ICAL.Timezone.localTimezone||this.zone==ICAL.Timezone.utcTimezone?0:this.zone.utcOffset(this)},toICALString:function(){var t=this.toString();return t.length>10?ICAL.design.icalendar.value["date-time"].toICAL(t):ICAL.design.icalendar.value.date.toICAL(t)},toString:function(){var t=this.year+"-"+ICAL.helpers.pad2(this.month)+"-"+ICAL.helpers.pad2(this.day);return this.isDate||(t+="T"+ICAL.helpers.pad2(this.hour)+":"+ICAL.helpers.pad2(this.minute)+":"+ICAL.helpers.pad2(this.second),this.zone===ICAL.Timezone.utcTimezone&&(t+="Z")),t},toJSDate:function(){return this.zone==ICAL.Timezone.localTimezone?this.isDate?new Date(this.year,this.month-1,this.day):new Date(this.year,this.month-1,this.day,this.hour,this.minute,this.second,0):new Date(1e3*this.toUnixTime())},_normalize:function(){return this._time.isDate,this._time.isDate&&(this._time.hour=0,this._time.minute=0,this._time.second=0),this.adjust(0,0,0,0),this},adjust:function(t,e,n,r,i){var s,a,o,u,h,c,l,d=0,f=0,m=i||this._time;if(m.isDate||(o=m.second+r,m.second=o%60,s=ICAL.helpers.trunc(o/60),m.second<0&&(m.second+=60,s--),u=m.minute+n+s,m.minute=u%60,a=ICAL.helpers.trunc(u/60),m.minute<0&&(m.minute+=60,a--),h=m.hour+e+a,m.hour=h%24,d=ICAL.helpers.trunc(h/24),m.hour<0&&(m.hour+=24,d--)),m.month>12?f=ICAL.helpers.trunc((m.month-1)/12):m.month<1&&(f=ICAL.helpers.trunc(m.month/12)-1),m.year+=f,m.month-=12*f,(c=m.day+t+d)>0)for(;l=ICAL.Time.daysInMonth(m.month,m.year),!(c<=l);)++m.month>12&&(m.year++,m.month=1),c-=l;else for(;c<=0;)1==m.month?(m.year--,m.month=12):m.month--,c+=ICAL.Time.daysInMonth(m.month,m.year);return m.day=c,this._cachedUnixTime=null,this},fromUnixTime:function(t){this.zone=ICAL.Timezone.utcTimezone;var e=ICAL.Time.epochTime.clone();e.adjust(0,0,0,t),this.year=e.year,this.month=e.month,this.day=e.day,this.hour=e.hour,this.minute=e.minute,this.second=Math.floor(e.second),this._cachedUnixTime=null},toUnixTime:function(){if(null!==this._cachedUnixTime)return this._cachedUnixTime;var t=this.utcOffset(),e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second-t);return this._cachedUnixTime=e/1e3,this._cachedUnixTime},toJSON:function(){for(var t,e=["year","month","day","hour","minute","second","isDate"],n=Object.create(null),r=0,i=e.length;r12?r:(r=n[t],2==t&&(r+=ICAL.Time.isLeapYear(e)),r)},ICAL.Time.isLeapYear=function(t){return t<=1752?t%4==0:t%4==0&&t%100!=0||t%400==0},ICAL.Time.fromDayOfYear=function(t,e){var n=e,r=t,i=new ICAL.Time;i.auto_normalize=!1;var s=ICAL.Time.isLeapYear(n)?1:0;if(r<1)return n--,s=ICAL.Time.isLeapYear(n)?1:0,r+=ICAL.Time.daysInYearPassedMonth[s][12],ICAL.Time.fromDayOfYear(r,n);if(r>ICAL.Time.daysInYearPassedMonth[s][12])return s=ICAL.Time.isLeapYear(n)?1:0,r-=ICAL.Time.daysInYearPassedMonth[s][12],n++,ICAL.Time.fromDayOfYear(r,n);i.year=n,i.isDate=!0;for(var a=11;a>=0;a--)if(r>ICAL.Time.daysInYearPassedMonth[s][a]){i.month=a+1,i.day=r-ICAL.Time.daysInYearPassedMonth[s][a];break}return i.auto_normalize=!0,i},ICAL.Time.fromStringv2=function(t){return new ICAL.Time({year:parseInt(t.substr(0,4),10),month:parseInt(t.substr(5,2),10),day:parseInt(t.substr(8,2),10),isDate:!0})},ICAL.Time.fromDateString=function(t){return new ICAL.Time({year:ICAL.helpers.strictParseInt(t.substr(0,4)),month:ICAL.helpers.strictParseInt(t.substr(5,2)),day:ICAL.helpers.strictParseInt(t.substr(8,2)),isDate:!0})},ICAL.Time.fromDateTimeString=function(t,e){if(t.length<19)throw new Error('invalid date-time value: "'+t+'"');var n;return t[19]&&"Z"===t[19]?n="Z":e&&(n=e.getParameter("tzid")),new ICAL.Time({year:ICAL.helpers.strictParseInt(t.substr(0,4)),month:ICAL.helpers.strictParseInt(t.substr(5,2)),day:ICAL.helpers.strictParseInt(t.substr(8,2)),hour:ICAL.helpers.strictParseInt(t.substr(11,2)),minute:ICAL.helpers.strictParseInt(t.substr(14,2)),second:ICAL.helpers.strictParseInt(t.substr(17,2)),timezone:n})},ICAL.Time.fromString=function(t){return t.length>10?ICAL.Time.fromDateTimeString(t):ICAL.Time.fromDateString(t)},ICAL.Time.fromJSDate=function(t,e){return(new ICAL.Time).fromJSDate(t,e)},ICAL.Time.fromData=function(t,e){return(new ICAL.Time).fromData(t,e)},ICAL.Time.now=function(){return ICAL.Time.fromJSDate(new Date,!1)},ICAL.Time.weekOneStarts=function(t,e){var n=ICAL.Time.fromData({year:t,month:1,day:1,isDate:!0}),r=n.dayOfWeek(),i=e||ICAL.Time.DEFAULT_WEEK_START;return r>ICAL.Time.THURSDAY&&(n.day+=7),i>ICAL.Time.THURSDAY&&(n.day-=7),n.day-=r-i,n},ICAL.Time.getDominicalLetter=function(t){var e=(t+(t/4|0)+(t/400|0)-(t/100|0)-1)%7;return ICAL.Time.isLeapYear(t)?"GFEDCBA"[(e+6)%7]+"GFEDCBA"[e]:"GFEDCBA"[e]},ICAL.Time.epochTime=ICAL.Time.fromData({year:1970,month:1,day:1,hour:0,minute:0,second:0,isDate:!1,timezone:"Z"}),ICAL.Time._cmp_attr=function(t,e,n){return t[n]>e[n]?1:t[n]4?d?n(u,1,2):n(u,3,2):null,second:4==c?n(u,2,2):6==c?n(u,4,2):8==c?n(u,6,2):null};return o="Z"==o?ICAL.Timezone.utcTimezone:o&&":"==o[3]?ICAL.UtcOffset.fromString(o):null,new ICAL.VCardTime(f,o,e)},function(){function t(t,e,n,r){var i=r;if("+"===r[0]&&(i=r.substr(1)),i=ICAL.helpers.strictParseInt(i),void 0!==e&&r '+e);if(void 0!==n&&r>n)throw new Error(t+': invalid value "'+r+'" must be < '+e);return i}var e={SU:ICAL.Time.SUNDAY,MO:ICAL.Time.MONDAY,TU:ICAL.Time.TUESDAY,WE:ICAL.Time.WEDNESDAY,TH:ICAL.Time.THURSDAY,FR:ICAL.Time.FRIDAY,SA:ICAL.Time.SATURDAY},n={};for(var r in e)e.hasOwnProperty(r)&&(n[e[r]]=r);ICAL.Recur=function(t){this.wrappedJSObject=this,this.parts={},t&&"object"==typeof t&&this.fromData(t)},ICAL.Recur.prototype={parts:null,interval:1,wkst:ICAL.Time.MONDAY,until:null,count:null,freq:null,icalclass:"icalrecur",icaltype:"recur",iterator:function(t){return new ICAL.RecurIterator({rule:this,dtstart:t})},clone:function(){return new ICAL.Recur(this.toJSON())},isFinite:function(){return!(!this.count&&!this.until)},isByCount:function(){return!(!this.count||this.until)},addComponent:function(t,e){var n=t.toUpperCase();n in this.parts?this.parts[n].push(e):this.parts[n]=[e]},setComponent:function(t,e){this.parts[t.toUpperCase()]=e.slice()},getComponent:function(t){var e=t.toUpperCase();return e in this.parts?this.parts[e].slice():[]},getNextOccurrence:function(t,e){var n,r=this.iterator(t);do{n=r.next()}while(n&&n.compare(e)<=0);return n&&e.zone&&(n.zone=e.zone),n},fromData:function(t){for(var e in t){var n=e.toUpperCase();n in u?Array.isArray(t[e])?this.parts[n]=t[e]:this.parts[n]=[t[e]]:this[e]=t[e]}this.interval&&"number"!=typeof this.interval&&o.INTERVAL(this.interval,this),this.wkst&&"number"!=typeof this.wkst&&(this.wkst=ICAL.Recur.icalDayToNumericDay(this.wkst)),!this.until||this.until instanceof ICAL.Time||(this.until=ICAL.Time.fromString(this.until))},toJSON:function(){var t=Object.create(null);t.freq=this.freq,this.count&&(t.count=this.count),this.interval>1&&(t.interval=this.interval);for(var e in this.parts)if(this.parts.hasOwnProperty(e)){var n=this.parts[e];Array.isArray(n)&&1==n.length?t[e.toLowerCase()]=n[0]:t[e.toLowerCase()]=ICAL.helpers.clone(this.parts[e])}return this.until&&(t.until=this.until.toString()),"wkst"in this&&this.wkst!==ICAL.Time.DEFAULT_WEEK_START&&(t.wkst=ICAL.Recur.numericDayToIcalDay(this.wkst)),t},toString:function(){var t="FREQ="+this.freq;this.count&&(t+=";COUNT="+this.count),this.interval>1&&(t+=";INTERVAL="+this.interval);for(var e in this.parts)this.parts.hasOwnProperty(e)&&(t+=";"+e+"="+this.parts[e]);return this.until&&(t+=";UNTIL="+this.until.toICALString()),"wkst"in this&&this.wkst!==ICAL.Time.DEFAULT_WEEK_START&&(t+=";WKST="+ICAL.Recur.numericDayToIcalDay(this.wkst)),t}},ICAL.Recur.icalDayToNumericDay=function(t){return e[t]},ICAL.Recur.numericDayToIcalDay=function(t){return n[t]};var i=/^(SU|MO|TU|WE|TH|FR|SA)$/,s=/^([+-])?(5[0-3]|[1-4][0-9]|[1-9])?(SU|MO|TU|WE|TH|FR|SA)$/,a=["SECONDLY","MINUTELY","HOURLY","DAILY","WEEKLY","MONTHLY","YEARLY"],o={FREQ:function(t,e,n){if(-1===a.indexOf(t))throw new Error('invalid frequency "'+t+'" expected: "'+a.join(", ")+'"');e.freq=t},COUNT:function(t,e,n){e.count=ICAL.helpers.strictParseInt(t)},INTERVAL:function(t,e,n){e.interval=ICAL.helpers.strictParseInt(t),e.interval<1&&(e.interval=1)},UNTIL:function(t,e,n){t.length>10?e.until=ICAL.design.icalendar.value["date-time"].fromICAL(t):e.until=ICAL.design.icalendar.value.date.fromICAL(t),n||(e.until=ICAL.Time.fromString(e.until))},WKST:function(t,e,n){if(!i.test(t))throw new Error('invalid WKST value "'+t+'"');e.wkst=ICAL.Recur.icalDayToNumericDay(t)}},u={BYSECOND:t.bind(this,"BYSECOND",0,60),BYMINUTE:t.bind(this,"BYMINUTE",0,59),BYHOUR:t.bind(this,"BYHOUR",0,23),BYDAY:function(t){if(s.test(t))return t;throw new Error('invalid BYDAY value "'+t+'"')},BYMONTHDAY:t.bind(this,"BYMONTHDAY",-31,31),BYYEARDAY:t.bind(this,"BYYEARDAY",-366,366),BYWEEKNO:t.bind(this,"BYWEEKNO",-53,53),BYMONTH:t.bind(this,"BYMONTH",0,12),BYSETPOS:t.bind(this,"BYSETPOS",-366,366)};ICAL.Recur.fromString=function(t){var e=ICAL.Recur._stringToData(t,!1);return new ICAL.Recur(e)},ICAL.Recur.fromData=function(t){return new ICAL.Recur(t)},ICAL.Recur._stringToData=function(t,e){for(var n=Object.create(null),r=t.split(";"),i=r.length,s=0;s=0||n<0)&&(this.last.day+=n)}else{var r=ICAL.Recur.numericDayToIcalDay(this.dtstart.dayOfWeek());t.BYDAY=[r]}if("YEARLY"==this.rule.freq){for(;this.expand_year_days(this.last.year),!(this.days.length>0);)this.increment_year(this.rule.interval);this._nextByYearDay()}if("MONTHLY"==this.rule.freq&&this.has_by_data("BYDAY")){var i=null,s=this.last.clone(),a=ICAL.Time.daysInMonth(this.last.month,this.last.year);for(var o in this.by_data.BYDAY)if(this.by_data.BYDAY.hasOwnProperty(o)){this.last=s.clone();var u=this.ruleDayOfWeek(this.by_data.BYDAY[o]),e=u[0],h=u[1],c=this.last.nthWeekDay(h,e);if(e>=6||e<=-6)throw new Error("Malformed values in BYDAY part");if(c>a||c<=0){if(i&&i.month==s.month)continue;for(;c>a||c<=0;)this.increment_month(),a=ICAL.Time.daysInMonth(this.last.month,this.last.year),c=this.last.nthWeekDay(h,e)}this.last.day=c,(!i||this.last.compare(i)<0)&&(i=this.last.clone())}if(this.last=i.clone(),this.has_by_data("BYMONTHDAY")&&this._byDayAndMonthDay(!0),this.last.day>a||0==this.last.day)throw new Error("Malformed values in BYDAY part")}else if(this.has_by_data("BYMONTHDAY")&&this.last.day<0){a=ICAL.Time.daysInMonth(this.last.month,this.last.year);this.last.day=a+this.last.day+1}},next:function(){var t=this.last?this.last.clone():null;if(this.rule.count&&this.occurrence_number>=this.rule.count||this.rule.until&&this.last.compare(this.rule.until)>0)return this.completed=!0,null;if(0==this.occurrence_number&&this.last.compare(this.dtstart)>=0)return this.occurrence_number++,this.last;var e;do{switch(e=1,this.rule.freq){case"SECONDLY":this.next_second();break;case"MINUTELY":this.next_minute();break;case"HOURLY":this.next_hour();break;case"DAILY":this.next_day();break;case"WEEKLY":this.next_week();break;case"MONTHLY":e=this.next_month();break;case"YEARLY":this.next_year();break;default:return null}}while(!this.check_contracting_rules()||this.last.compare(this.dtstart)<0||!e);if(0==this.last.compare(t))throw new Error("Same occurrence found twice, protecting you from death by recursion");return this.rule.until&&this.last.compare(this.rule.until)>0?(this.completed=!0,null):(this.occurrence_number++,this.last)},next_second:function(){return this.next_generic("BYSECOND","SECONDLY","second","minute")},increment_second:function(t){return this.increment_generic(t,"second",60,"minute")},next_minute:function(){return this.next_generic("BYMINUTE","MINUTELY","minute","hour","next_second")},increment_minute:function(t){return this.increment_generic(t,"minute",60,"hour")},next_hour:function(){return this.next_generic("BYHOUR","HOURLY","hour","monthday","next_minute")},increment_hour:function(t){this.increment_generic(t,"hour",24,"monthday")},next_day:function(){this.by_data;var t="DAILY"==this.rule.freq;return 0==this.next_hour()?0:(t?this.increment_monthday(this.rule.interval):this.increment_monthday(1),0)},next_week:function(){var t=0;if(0==this.next_weekday_by_week())return t;if(this.has_by_data("BYWEEKNO")){++this.by_indices.BYWEEKNO;this.by_indices.BYWEEKNO==this.by_data.BYWEEKNO.length&&(this.by_indices.BYWEEKNO=0,t=1),this.last.month=1,this.last.day=1;var e=this.by_data.BYWEEKNO[this.by_indices.BYWEEKNO];this.last.day+=7*e,t&&this.increment_year(1)}else this.increment_monthday(7*this.rule.interval);return t},normalizeByMonthDayRules:function(t,e,n){for(var r,i=ICAL.Time.daysInMonth(e,t),s=[],a=0,o=n.length;ai)){if(r<0)r=i+(r+1);else if(0===r)continue;-1===s.indexOf(r)&&s.push(r)}return s.sort(function(t,e){return t-e})},_byDayAndMonthDay:function(t){function e(){for(a=ICAL.Time.daysInMonth(l.last.month,l.last.year),r=l.normalizeByMonthDayRules(l.last.year,l.last.month,l.by_data.BYMONTHDAY),s=r.length;r[u]<=d&&(!t||r[u]!=d)&&ua)n();else{var m=r[u++];if(m>=i){d=m;for(var p=0;pe&&(this.last.day=1,this.increment_month(),this.is_day_in_byday(this.last)?this.has_by_data("BYSETPOS")&&!this.check_set_position(1)||(t=1):t=0)}else if(this.has_by_data("BYMONTHDAY")){++this.by_indices.BYMONTHDAY>=this.by_data.BYMONTHDAY.length&&(this.by_indices.BYMONTHDAY=0,this.increment_month());e=ICAL.Time.daysInMonth(this.last.month,this.last.year);(s=this.by_data.BYMONTHDAY[this.by_indices.BYMONTHDAY])<0&&(s=e+s+1),s>e?(this.last.day=1,t=this.is_day_in_byday(this.last)):this.last.day=s}else{this.increment_month();e=ICAL.Time.daysInMonth(this.last.month,this.last.year);this.by_data.BYMONTHDAY[0]>e?t=0:this.last.day=this.by_data.BYMONTHDAY[0]}return t},next_weekday_by_week:function(){var t=0;if(0==this.next_hour())return t;if(!this.has_by_data("BYDAY"))return 1;for(;;){var e=new ICAL.Time;++this.by_indices.BYDAY==Object.keys(this.by_data.BYDAY).length&&(this.by_indices.BYDAY=0,t=1);var n=this.by_data.BYDAY[this.by_indices.BYDAY],r=this.ruleDayOfWeek(n)[1];(r-=this.rule.wkst)<0&&(r+=7),e.year=this.last.year,e.month=this.last.month,e.day=this.last.day;var i=e.startDoyWeek(this.rule.wkst);if(!(r+i<1)||t){var s=ICAL.Time.fromDayOfYear(i+r,this.last.year);return this.last.year=s.year,this.last.month=s.month,this.last.day=s.day,t}}},next_year:function(){if(0==this.next_hour())return 0;if(++this.days_index==this.days.length){this.days_index=0;do{this.increment_year(this.rule.interval),this.expand_year_days(this.last.year)}while(0==this.days.length)}return this._nextByYearDay(),1},_nextByYearDay:function(){var t=this.days[this.days_index],e=this.last.year;t<1&&(t+=1,e+=1);var n=ICAL.Time.fromDayOfYear(t,e);this.last.day=n.day,this.last.month=n.month},ruleDayOfWeek:function(t){var e=t.match(/([+-]?[0-9])?(MO|TU|WE|TH|FR|SA|SU)/);if(e){var n=parseInt(e[1]||0,10);return t=ICAL.Recur.icalDayToNumericDay(e[2]),[n,t]}return[0,0]},next_generic:function(t,e,n,r,i){var s=t in this.by_data,a=this.rule.freq==e,o=0;if(i&&0==this[i]())return o;if(s){++this.by_indices[t];var u=this.by_data[t];this.by_indices[t]==u.length&&(this.by_indices[t]=0,o=1),this.last[n]=u[this.by_indices[t]]}else a&&this["increment_"+n](this.rule.interval);return s&&o&&a&&this["increment_"+r](1),o},increment_monthday:function(t){for(var e=0;en&&(this.last.day-=n,this.increment_month())}},increment_month:function(){if(this.last.day=1,this.has_by_data("BYMONTH"))++this.by_indices.BYMONTH==this.by_data.BYMONTH.length&&(this.by_indices.BYMONTH=0,this.increment_year(1)),this.last.month=this.by_data.BYMONTH[this.by_indices.BYMONTH];else{"MONTHLY"==this.rule.freq?this.last.month+=this.rule.interval:this.last.month++,this.last.month--;var t=ICAL.helpers.trunc(this.last.month/12);this.last.month%=12,this.last.month++,0!=t&&this.increment_year(t)}},increment_year:function(t){this.last.year+=t},increment_generic:function(t,e,n,r){this.last[e]+=t;var i=ICAL.helpers.trunc(this.last[e]/n);this.last[e]%=n,0!=i&&this["increment_"+r](i)},has_by_data:function(t){return t in this.rule.parts},expand_year_days:function(t){var e=new ICAL.Time;this.days=[];var n={},r=["BYDAY","BYWEEKNO","BYMONTHDAY","BYMONTH","BYYEARDAY"];for(var i in r)if(r.hasOwnProperty(i)){var s=r[i];s in this.rule.parts&&(n[s]=this.rule.parts[s])}if("BYMONTH"in n&&"BYWEEKNO"in n){var a=1,o={};e.year=t,e.isDate=!0;for(var u=0;u0?(S=z+7*(N-1))<=I&&this.days.push(v+S):(S=B+7*(N+1))>0&&this.days.push(v+S)}}this.days.sort(function(t,e){return t-e})}else if(2==d&&"BYDAY"in n&&"BYMONTHDAY"in n){j=this.expand_by_day(t);for(var P in j)if(j.hasOwnProperty(P)){var b=j[P],M=ICAL.Time.fromDayOfYear(b,t);this.by_data.BYMONTHDAY.indexOf(M.day)>=0&&this.days.push(b)}}else if(3==d&&"BYDAY"in n&&"BYMONTHDAY"in n&&"BYMONTH"in n){j=this.expand_by_day(t);for(var P in j)if(j.hasOwnProperty(P)){var b=j[P],M=ICAL.Time.fromDayOfYear(b,t);this.by_data.BYMONTH.indexOf(M.month)>=0&&this.by_data.BYMONTHDAY.indexOf(M.day)>=0&&this.days.push(b)}}else if(2==d&&"BYDAY"in n&&"BYWEEKNO"in n){var j=this.expand_by_day(t);for(var P in j)if(j.hasOwnProperty(P)){var b=j[P],k=(M=ICAL.Time.fromDayOfYear(b,t)).weekNumber(this.rule.wkst);this.by_data.BYWEEKNO.indexOf(k)&&this.days.push(b)}}else 3==d&&"BYDAY"in n&&"BYWEEKNO"in n&&"BYMONTHDAY"in n||(this.days=1==d&&"BYYEARDAY"in n?this.days.concat(this.by_data.BYYEARDAY):[]);return 0},expand_by_day:function(t){var e=[],n=this.last.clone();n.year=t,n.month=1,n.day=1,n.isDate=!0;var r=n.dayOfWeek();n.month=12,n.day=31,n.isDate=!0;var i=n.dayOfWeek(),s=n.dayOfYear();for(var a in this.by_data.BYDAY)if(this.by_data.BYDAY.hasOwnProperty(a)){var o=this.by_data.BYDAY[a],u=this.ruleDayOfWeek(o),h=u[0],c=u[1];if(0==h)for(var l=(c+7-r)%7+1;l<=s;l+=7)e.push(l);else if(h>0){var d;d=c>=r?c-r+1:c-r+8,e.push(d+7*(h-1))}else{var f;h=-h,f=c<=i?s-i+c:s-i+c-7,e.push(f-7*(h-1))}}return e},is_day_in_byday:function(t){for(var e in this.by_data.BYDAY)if(this.by_data.BYDAY.hasOwnProperty(e)){var n=this.by_data.BYDAY[e],r=this.ruleDayOfWeek(n),i=r[0],s=r[1],a=t.dayOfWeek();if(0==i&&s==a||t.nthWeekDay(s,i)==t.day)return 1}return 0},check_set_position:function(t){return!!this.has_by_data("BYSETPOS")&&-1!==this.by_data.BYSETPOS.indexOf(t)},sort_bypart_rules:function(t,e){if(t in e){var n=0;"BYYEARDAY"==t?n=ICAL.Time.isLeapYear(this.last.year)?367:366:"BYMONTHDAY"==t&&(n=ICAL.Time.daysInMonth(this.last.month,this.last.year)+1);e[t].sort(function(t,e){return t<0&&(t+=n),e<0&&(e+=n),t-e})}},sort_byday_rules:function(t,e){for(var n=0;ns){var a=t[n];t[n]=t[r],t[r]=a}}},check_contract_restriction:function(e,n){var r=t._indexMap[e],i=t._expandMap[this.rule.freq][r],s=!1;if(e in this.by_data&&i==t.CONTRACT){var a=this.by_data[e];for(var o in a)if(a.hasOwnProperty(o)&&a[o]==n){s=!0;break}}else s=!0;return s},check_contracting_rules:function(){var t=this.last.dayOfWeek(),e=this.last.weekNumber(this.rule.wkst),n=this.last.dayOfYear();return this.check_contract_restriction("BYSECOND",this.last.second)&&this.check_contract_restriction("BYMINUTE",this.last.minute)&&this.check_contract_restriction("BYHOUR",this.last.hour)&&this.check_contract_restriction("BYDAY",ICAL.Recur.numericDayToIcalDay(t))&&this.check_contract_restriction("BYWEEKNO",e)&&this.check_contract_restriction("BYMONTHDAY",this.last.day)&&this.check_contract_restriction("BYMONTH",this.last.month)&&this.check_contract_restriction("BYYEARDAY",n)},setup_defaults:function(e,n,r){var i=t._indexMap[e];return t._expandMap[this.rule.freq][i]!=t.CONTRACT&&(e in this.by_data||(this.by_data[e]=[r]),this.rule.freq!=n)?this.by_data[e][0]:r},toJSON:function(){var t=Object.create(null);return t.initialized=this.initialized,t.rule=this.rule.toJSON(),t.dtstart=this.dtstart.toJSON(),t.by_data=this.by_data,t.days=this.days,t.last=this.last.toJSON(),t.by_indices=this.by_indices,t.occurrence_number=this.occurrence_number,t}},t._indexMap={BYSECOND:0,BYMINUTE:1,BYHOUR:2,BYDAY:3,BYMONTHDAY:4,BYYEARDAY:5,BYWEEKNO:6,BYMONTH:7,BYSETPOS:8},t._expandMap={SECONDLY:[1,1,1,1,1,1,1,1],MINUTELY:[2,1,1,1,1,1,1,1],HOURLY:[2,2,1,1,1,1,1,1],DAILY:[2,2,2,1,1,1,1,1],WEEKLY:[2,2,2,2,3,3,1,1],MONTHLY:[2,2,2,2,2,3,3,1],YEARLY:[2,2,2,2,2,2,2,2]},t.UNKNOWN=0,t.CONTRACT=1,t.EXPAND=2,t.ILLEGAL=3,t}(),ICAL.RecurExpansion=function(){function t(t){return ICAL.helpers.formatClassType(t,ICAL.Time)}function e(t,e){return t.compare(e)}function n(t){return t.hasProperty("rdate")||t.hasProperty("rrule")||t.hasProperty("recurrence-id")}function r(t){this.ruleDates=[],this.exDates=[],this.fromData(t)}return r.prototype={complete:!1,ruleIterators:null,ruleDates:null,exDates:null,ruleDateInc:0,exDateInc:0,exDate:null,ruleDate:null,dtstart:null,last:null,fromData:function(e){var n=ICAL.helpers.formatClassType(e.dtstart,ICAL.Time);if(!n)throw new Error(".dtstart (ICAL.Time) must be given");if(this.dtstart=n,e.component)this._init(e.component);else{if(this.last=t(e.last)||n.clone(),!e.ruleIterators)throw new Error(".ruleIterators or .component must be given");this.ruleIterators=e.ruleIterators.map(function(t){return ICAL.helpers.formatClassType(t,ICAL.RecurIterator)}),this.ruleDateInc=e.ruleDateInc,this.exDateInc=e.exDateInc,e.ruleDates&&(this.ruleDates=e.ruleDates.map(t),this.ruleDate=this.ruleDates[this.ruleDateInc]),e.exDates&&(this.exDates=e.exDates.map(t),this.exDate=this.exDates[this.exDateInc]),void 0!==e.complete&&(this.complete=e.complete)}},next:function(){for(var t,e,n,r=0;;){if(r++>500)throw new Error("max tries have occured, rule may be impossible to forfill.");if(e=this.ruleDate,t=this._nextRecurrenceIter(this.last),!e&&!t){this.complete=!0;break}if((!e||t&&e.compare(t.last)>0)&&(e=t.last.clone(),t.next()),this.ruleDate===e&&this._nextRuleDay(),this.last=e,!this.exDate||((n=this.exDate.compare(this.last))<0&&this._nextExDay(),0!==n))return this.last;this._nextExDay()}},toJSON:function(){function t(t){return t.toJSON()}var e=Object.create(null);return e.ruleIterators=this.ruleIterators.map(t),this.ruleDates&&(e.ruleDates=this.ruleDates.map(t)),this.exDates&&(e.exDates=this.exDates.map(t)),e.ruleDateInc=this.ruleDateInc,e.exDateInc=this.exDateInc,e.last=this.last.toJSON(),e.dtstart=this.dtstart.toJSON(),e.complete=this.complete,e},_extractDates:function(t,n){for(var r,i=[],s=t.getAllProperties(n),a=s.length,o=0;o0)&&(r=e);return r}},r}(),ICAL.Event=function(){function t(t,e){t instanceof ICAL.Component||(e=t,t=null),this.component=t||new ICAL.Component("vevent"),this._rangeExceptionCache=Object.create(null),this.exceptions=Object.create(null),this.rangeExceptions=[],e&&e.strictExceptions&&(this.strictExceptions=e.strictExceptions),e&&e.exceptions?e.exceptions.forEach(this.relateException,this):this.component.parent&&!this.isRecurrenceException()&&this.component.parent.getAllSubcomponents("vevent").forEach(function(t){t.hasProperty("recurrence-id")&&this.relateException(t)},this)}function e(t,e){return t[0]>e[0]?1:e[0]>t[0]?-1:0}return t.prototype={THISANDFUTURE:"THISANDFUTURE",exceptions:null,strictExceptions:!1,relateException:function(t){if(this.isRecurrenceException())throw new Error("cannot relate exception to exceptions");if(t instanceof ICAL.Component&&(t=new ICAL.Event(t)),this.strictExceptions&&t.uid!==this.uid)throw new Error("attempted to relate unrelated exception");var n=t.recurrenceId.toString();if(this.exceptions[n]=t,t.modifiesFuture()){var r=[t.recurrenceId.toUnixTime(),n],i=ICAL.helpers.binsearchInsert(this.rangeExceptions,r,e);this.rangeExceptions.splice(i,0,r)}},modifiesFuture:function(){return!!this.component.hasProperty("recurrence-id")&&this.component.getFirstProperty("recurrence-id").getParameter("range")===this.THISANDFUTURE},findRangeException:function(t){if(!this.rangeExceptions.length)return null;var n=t.toUnixTime(),r=ICAL.helpers.binsearchInsert(this.rangeExceptions,[n],e);if((r-=1)<0)return null;var i=this.rangeExceptions[r];return n 28 in march + this.sort_bypart_rules("BYMONTHDAY", parts); + this.last.day = this.setup_defaults("BYMONTHDAY", "DAILY", this.dtstart.day); + + this.sort_bypart_rules("BYYEARDAY", parts); + if (this.rule.freq == "WEEKLY") { if ("BYDAY" in parts) { var bydayParts = this.ruleDayOfWeek(parts.BYDAY[0]); @@ -1300,6 +1314,27 @@ ICAL.RecurIterator = (function() { return false; }, + sort_bypart_rules: function icalrecur_sort_bypart(aPartName, aParts) { + if (aPartName in aParts) { + var offset = 0; + if (aPartName == "BYYEARDAY") { + offset = ICAL.Time.isLeapYear(this.last.year)? 367 : 366; + } else if (aPartName == "BYMONTHDAY") { + offset = ICAL.Time.daysInMonth(this.last.month, this.last.year) + 1; + } + var comparator = function(a, b) { + if (a < 0) { + a += offset; + } + if (b < 0) { + b += offset; + } + return a - b; + }; + aParts[aPartName].sort(comparator); + } + }, + sort_byday_rules: function icalrecur_sort_byday_rules(aRules, aWeekStart) { for (var i = 0; i < aRules.length; i++) { for (var j = 0; j < i; j++) { diff --git a/test/recur_iterator_test.js b/test/recur_iterator_test.js index 46d62315..9138e58b 100644 --- a/test/recur_iterator_test.js +++ b/test/recur_iterator_test.js @@ -243,6 +243,17 @@ suite('recur_iterator', function() { ] }); + //secondly + unsorted bysecond + testRRULE('FREQ=SECONDLY;BYSECOND=3,2,1;UNTIL=20130101T000003Z', { + dtStart: '2013-01-01T00:00:01', + until: true, + dates: [ + '2013-01-01T00:00:01', + '2013-01-01T00:00:02', + '2013-01-01T00:00:03' + ] + }); + // Simple minutely testRRULE('FREQ=MINUTELY;INTERVAL=3;COUNT=3', { byCount: true, @@ -253,6 +264,16 @@ suite('recur_iterator', function() { ] }); + //minutely + unsorted byminute + testRRULE('FREQ=MINUTELY;BYMINUTE=3,2,1;UNTIL=20130101T000200Z', { + dtStart: '2013-01-01T00:01:00', + until: true, + dates: [ + '2013-01-01T00:01:00', + '2013-01-01T00:02:00' + ] + }); + //simple hourly testRRULE('FREQ=HOURLY;INTERVAL=3;COUNT=3', { byCount: true, @@ -262,6 +283,16 @@ suite('recur_iterator', function() { '2015-04-30T14:00:00' ] }); + + //hourly + unsorted byhour + testRRULE('FREQ=HOURLY;BYHOUR=3,2,1;UNTIL=20130101T020000Z', { + dtStart: '2013-01-01T01:00:00', + until: true, + dates: [ + '2013-01-01T01:00:00', + '2013-01-01T02:00:00' + ] + }); }); suite('DAILY', function() { @@ -687,6 +718,27 @@ suite('recur_iterator', function() { ] }); + //monthly + unsorted bymonthday + testRRULE('FREQ=MONTHLY;BYMONTHDAY=3,2,1;UNTIL=20130102T000000Z', { + dtStart: '2013-01-01', + until: true, + dates: [ + '2013-01-01', + '2013-01-02' + ] + }); + + //monthly + unsorted bymonth + testRRULE('FREQ=MONTHLY;BYMONTH=3,2,1;UNTIL=20130301T000000Z', { + dtStart: '2013-01-01', + until: true, + dates: [ + '2013-01-01', + '2013-02-01', + '2013-03-01' + ] + }); + testRRULE('FREQ=MONTHLY;BYDAY=MO,FR;BYMONTHDAY=1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31;COUNT=4', { dtStart: '2015-03-01T08:00:00Z', byCount: true, @@ -732,6 +784,37 @@ suite('recur_iterator', function() { "2015-04-19T08:00:00Z" ] }) + + //monthly + unsorted positive, negative bymonthday + testRRULE('FREQ=MONTHLY;BYMONTHDAY=-1,1;UNTIL=20130201T000000Z', { + dtStart: '2013-01-01', + until: true, + dates: [ + '2013-01-01', + '2013-01-31', + '2013-02-01' + ] + }); + + //monthly + unsorted positive, negative bymonthday + testRRULE('FREQ=MONTHLY;BYMONTHDAY=28,-2;UNTIL=20130227T000000Z', { + dtStart: '2013-02-25', + until: true, + dates: [ + '2013-02-27' + ] + }); + + //monthly + unsorted positive, negative bymonthday + testRRULE('FREQ=MONTHLY;BYMONTHDAY=31,-2;UNTIL=20130427T000000Z', { + dtStart: '2013-02-25', + until: true, + dates: [ + '2013-02-27', + '2013-03-30', + '2013-03-31', + ] + }); }); suite('YEARLY', function() { @@ -984,6 +1067,36 @@ suite('recur_iterator', function() { ] }); + //yearly + unsorted bymonth + testRRULE('FREQ=YEARLY;BYMONTH=3,2,1;UNTIL=20130201T000000Z', { + dtStart: '2013-01-01', + until: true, + dates: [ + '2013-01-01', + '2013-02-01' + ] + }); + + //yearly + unsorted byyearday + testRRULE('FREQ=YEARLY;BYYEARDAY=3,2,1;UNTIL=20130102T000000Z', { + dtStart: '2013-01-01', + until: true, + dates: [ + '2013-01-01', + '2013-01-02' + ] + }); + + //yearly + unsorted positive, negative bymonthday + testRRULE('FREQ=YEARLY;BYMONTH=3;BYMONTHDAY=-2,28;UNTIL=20130330T000000Z', { + dtStart: '2013-02-25', + until: true, + dates: [ + '2013-03-28', + '2013-03-30', + ] + }); + /* * Leap-year test for February 29th *