From c0d49fbc2d7b6bdb89c4ec94eb7bd4c71bc508ad Mon Sep 17 00:00:00 2001 From: Kalyanasundaram Nachiappan Date: Wed, 5 Jul 2017 14:22:33 -0700 Subject: [PATCH 1/3] Add Validation for Bysetpos during initialisation --- build/ical.js | 47 ++++- build/ical.min.js | 2 +- build/ical.min.js.map | 2 +- lib/ical/recur_iterator.js | 47 ++++- test/recur_iterator_test.js | 377 +++++++++++++++++++++++++++++++++++- 5 files changed, 466 insertions(+), 9 deletions(-) diff --git a/build/ical.js b/build/ical.js index e3481e2d..cf0e6f1b 100644 --- a/build/ical.js +++ b/build/ical.js @@ -7090,7 +7090,7 @@ ICAL.RecurIterator = (function() { return null; } - if (this.occurrence_number == 0 && this.last.compare(this.dtstart) >= 0) { + if (this.occurrence_number == 0 && (this.last.compare(this.dtstart) >= 0 && this.validate_bysetpos())) { // First of all, give the instance that was initialized this.occurrence_number++; return this.last; @@ -7223,6 +7223,51 @@ ICAL.RecurIterator = (function() { return end_of_data; }, + /* + * Checks if the computed last date is valid for given bysetpos rule + */ + validate_bysetpos: function () { + if (!this.has_by_data("BYSETPOS")) { + return true; + } + + var currentJson = this.rule.toJSON(); + delete currentJson.bysetpos; + delete currentJson.count; + var recurWithoutBysetPos = ICAL.Recur.fromData(currentJson); + var iterator = recurWithoutBysetPos.iterator(this.dtstart); + var datesList = []; + var endDate; + var date = iterator.next(); + if(date == null) { + return false; + } + if(this.rule.freq == "YEARLY") { + endDate = date.endOfYear(); + } else if(this.rule.freq == "MONTHLY") { + endDate = date.endOfMonth(); + } else if(this.rule.freq == "WEEK") { + endDate = date.endOfWeek(); + } else { + return true; + } + datesList.push(date.clone()); + while(date = iterator.next()) { + if(endDate.compare(date) < 0) { + break; + } + datesList.push(date.clone()); + } + + var isValidBysetPos = false; + for(var idx = 0; idx < datesList.length; idx++) { + if(this.last.compare(datesList[idx]) == 0) { + isValidBysetPos = this.check_set_position(idx + 1) || this.check_set_position(idx - datesList.length); + } + } + return isValidBysetPos; + }, + /** * Normalize each by day rule for a given year/month. * Takes into account ordering and negative rules diff --git a/build/ical.min.js b/build/ical.min.js index a025f385..6b13f236 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[r-1]))return r;r+=1}return-1},binsearchInsert:function(t,e,r){if(!t.length)return 0;for(var n,i,a=0,s=t.length-1;a<=s;)if(n=a+Math.floor((s-a)/2),(i=r(e,t[n]))<0)s=n-1;else{if(!(i>0))break;a=n+1}return i<0?n:i>0?n+1:n},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 r=[],n=0;n11?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 r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var n=t[r];"until"==r?n=n.length>10?T["date-time"].toICAL(n):T.date.toICAL(n):"wkst"==r?"number"==typeof n&&(n=ICAL.Recur.numericDayToIcalDay(n)):Array.isArray(n)&&(n=n.join(",")),e+=r.toUpperCase()+"="+n+";"}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),r=e[0],n=e[1];return 6==n.length?n=n.substr(0,2)+":"+n.substr(2,2)+":"+n.substr(4,2):4==n.length&&"-"!=n[0]?n=n.substr(0,2)+":"+n.substr(2,2):5==n.length&&(n=n.substr(0,3)+":"+n.substr(3,2)),5!=r.length||"-"!=r[0]&&"+"!=r[0]||(r=r.substr(0,3)+":"+r.substr(3)),n+r},toICAL:function(t){var e=_.time._splitZone(t),r=e[0],n=e[1];return 8==n.length?n=n.substr(0,2)+n.substr(3,2)+n.substr(6,2):5==n.length&&"-"!=n[0]?n=n.substr(0,2)+n.substr(3,2):6==n.length&&(n=n.substr(0,3)+n.substr(4,2)),6!=r.length||"-"!=r[0]&&"+"!=r[0]||(r=r.substr(0,3)+r.substr(4)),n+r},_splitZone:function(t,e){var r,n,i=t.length-1,a=t.length-(e?5:6),s=t[a];return"Z"==t[i]?(r=t[i],n=t.substr(0,i)):t.length>6&&("-"==s||"+"==s)?(r=t.substr(a),n=t.substr(0,a)):(r="",n=t),[r,n]}},"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()}}}),Y={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}},b=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},E={value:D,param:Y,property:b},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(r){"string"==typeof r[0]&&(r=[r]);for(var n=0,i=r.length,a="";n0&&("version"!==n[1][0][0]||"4.0"!==n[1][0][3])&&(c="vcard3"),i=i||r.getDesignSet(c);u1)throw new t("invalid ical body. component began but did not end");return n=null,1==i.length?i[0]:i}var r=/[^ \t]/,n=ICAL.design,i=ICAL.helpers;t.prototype=Error.prototype,e.property=function(t,r){var i={component:[[],[]],designSet:r||n.defaultSet};return e._handleContentLine(t,i),i.component[1][0]},e.component=function(t){return e(t)},e.ParserError=t,e._handleContentLine=function(r,i){var a,s,o,u,h=r.indexOf(":"),c=r.indexOf(";"),l={};-1!==c&&-1!==h&&c>h&&(c=-1);var d;if(-1!==c){if(o=r.substring(0,c).toLowerCase(),-1==(d=e._parseParameters(r.substring(c),0,i.designSet))[2])throw new t("Invalid parameters in '"+r+"'");if(l=d[0],a=d[1].length+d[2]+c,-1===(s=r.substring(a).indexOf(":")))throw new t("Missing parameter value in '"+r+"'");u=r.substring(a+s+1)}else{if(-1===h)throw new t('invalid line (no token ";" or ":") "'+r+'"');if(o=r.substring(0,h).toLowerCase(),u=r.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=n.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=n.getDesignSet("vcard3")),i.component[1].push(C)},e._parseValue=function(t,e,r,n){return e in r.value&&"fromICAL"in r.value[e]?r.value[e].fromICAL(t,n):t},e._parseParameters=function(r,n,a){for(var s,o,u,h,c,l,d=n,f=0,m={},p=-1;!1!==f&&-1!==(f=i.unescapedIndexOf(r,"=",f+1));){if(0==(s=r.substr(d+1,f-d-1)).length)throw new t("Empty parameter name in '"+r+"'");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+'"'))),'"'===r[f+1]){if(p=f+2,f=i.unescapedIndexOf(r,'"',p),c&&-1!=f)for(var y=!0;y;)r[f+1]==c&&'"'==r[f+2]?f=i.unescapedIndexOf(r,'"',f+3):y=!1;if(-1===f)throw new t('invalid line (no matching double quote) "'+r+'"');u=r.substr(p,f-p),-1===(d=i.unescapedIndexOf(r,";",f))&&(f=!1)}else{p=f+1;var A=i.unescapedIndexOf(r,";",p),C=i.unescapedIndexOf(r,":",p);-1!==C&&A>C?(A=C,f=!1):-1===A?(A=-1===C?r.length:C,f=!1):(d=A,f=A),u=r.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,r,n,a,s,o,u){var h,c=0,l=0;if(0===r.length)return t;for(;-1!==(c=i.unescapedIndexOf(t,r,l));)h=t.substr(l,c-l),h=s?e._parseMultiValue(h,s,n,[],null,o,u):e._parseValue(h,n,o,u),a.push(h),l=c+r.length;return h=t.substr(l),h=s?e._parseMultiValue(h,s,n,[],null,o,u):e._parseValue(h,n,o,u),a.push(h),1==a.length?a[0]:a},e._eachLine=function(t,e){var n,i,a,s=t.length,o=t.search(r),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?n+=t.substr(o+1,u-o-(a+1)):(n&&e(null,n),n=t.substr(o,u-o-a)),o=u}while(u!==s);(n=n.trim()).length&&e(null,n)},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 r=new t(this.jCal[2][e],this);return this._hydratedComponentCount++,this._components[e]=r},_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 r=0,n=this.jCal[2],i=n.length;r=0;s--)n&&a[s][e]!==n||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 r=new ICAL.Property(t);return r.setValue(e),this.addProperty(r),r},updatePropertyWithValue:function(t,e){var r=this.getFirstProperty(t);return r?r.setValue(e):r=this.addPropertyWithValue(t,e),r},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,{},n.defaultType],this.jCal[r]=this.getDefaultType()):this.jCal=t,this._updateType()}var e=0,r=2,n=ICAL.design;return t.prototype={get type(){return this.jCal[r]},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==n.defaultType&&e&&(this.jCal[r]=this.getDefaultType(),this._updateType()),t},get _designSet(){return this.parent?this.parent._designSet:n.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 r=t.toLowerCase();"string"==typeof e&&r in this._designSet.param&&"multiValue"in this._designSet.param[r]&&(e=[e]),this.jCal[1][t]=e},removeParameter:function(t){delete this.jCal[1][t]},getDefaultType:function(){var t=this.jCal[e],r=this._designSet;if(t in r.property){var i=r.property[t];if("defaultType"in i)return i.defaultType}return n.defaultType},resetType:function(t){this.removeAllValues(),this.jCal[r]=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,r=[];e0&&"object"==typeof t[0]&&"icaltype"in t[0]&&this.resetType(t[0].icaltype),this.isDecorated)for(;rr)-(r>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 r=new t;return r.fromSeconds(e),r},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,r,n,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,r=a>>12&63,n=a>>6&63,i=63&a,c[u++]=s.charAt(e)+s.charAt(r)+s.charAt(n)+s.charAt(i)}while(o>16&255,r=s>>8&255,n=255&s,c[h++]=64==i?String.fromCharCode(e):64==a?String.fromCharCode(e,r):String.fromCharCode(e,r,n)}while(ur)-(e=0?n=r:i=-1,-1==i&&-1!=n)break;if((r+=i)<0)return 0;if(r>=this.changes.length)break}var s=this.changes[n];if(s.utcOffset-s.prevUtcOffset<0&&n>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[n-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 r=t;if(rICAL.Timezone.MAX_YEAR&&(r=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),r.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),r.push(a);return r},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,r){if(t.isDate||e.tzid==r.tzid||e==ICAL.Timezone.localTimezone||r==ICAL.Timezone.localTimezone)return t.zone=r,t;var n=e.utcOffset(t);return t.adjust(0,0,0,-n),n=r.utcOffset(t),t.adjust(0,0,0,n),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,r,n,i){return ICAL.Time.prototype.adjust.call(t,e,r,n,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,r){if(e instanceof ICAL.Component&&"vtimezone"===e.name&&(e=(r=new ICAL.Timezone(e)).tzid),!(r instanceof ICAL.Timezone))throw new TypeError("timezone must be ICAL.Timezone or ICAL.Component");t[e]=r},remove:function(e){return delete t[e]}};return e.reset(),e}(),ICAL.Time=function(t,e){this.wrappedJSObject=this;var r=this._time=Object.create(null);r.year=0,r.month=1,r.day=1,r.hour=0,r.minute=0,r.second=0,r.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,r,n,i,a,s){this.fromData({year:t,month:e,day:r,hour:n,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 r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if("icaltype"===r)continue;this[r]=t[r]}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 n=ICAL.TimezoneService.get(t.timezone);this.zone=n||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,r=this.month+(this.month<3?12:0),n=this.year-(this.month<3?1:0),i=e+n+ICAL.helpers.trunc(26*(r+1)/10)+ICAL.helpers.trunc(n/4);return i+=6*ICAL.helpers.trunc(n/100)+ICAL.helpers.trunc(n/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,r=this.clone();return r.day-=(this.dayOfWeek()+7-e)%7,r.isDate=!0,r.hour=0,r.minute=0,r.second=0,r},endOfWeek:function(t){var e=t||ICAL.Time.SUNDAY,r=this.clone();return r.day+=(7-this.dayOfWeek()+e-ICAL.Time.SUNDAY)%7,r.isDate=!0,r.hour=0,r.minute=0,r.second=0,r},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,r=this.dayOfWeek()-e;return r<0&&(r+=7),this.dayOfYear()-r},getDominicalLetter:function(){return ICAL.Time.getDominicalLetter(this.year)},nthWeekDay:function(t,e){var r,n=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,r=t}else s.day=n,i++,(r=s.dayOfWeek()-t)<0&&(r+=7),r=n-r;return r+=7*i,a+r},isNthWeekDay:function(t,e){var r=this.dayOfWeek();return 0===e&&r===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 r,n=this.clone();n.isDate=!0;var i=this.year;12==n.month&&n.day>25?(r=ICAL.Time.weekOneStarts(i+1,t),n.compare(r)<0?r=ICAL.Time.weekOneStarts(i,t):i++):(r=ICAL.Time.weekOneStarts(i,t),n.compare(r)<0&&(r=ICAL.Time.weekOneStarts(--i,t)));var a=n.subtractDate(r).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,r=this.second,n=this.minute,i=this.hour,a=this.day;r+=e*t.seconds,n+=e*t.minutes,i+=e*t.hours,a+=e*t.days,a+=7*e*t.weeks,this.second=r,this.minute=n,this.hour=i,this.day=a,this._cachedUnixTime=null},subtractDate:function(t){var e=this.toUnixTime()+this.utcOffset(),r=t.toUnixTime()+t.utcOffset();return ICAL.Duration.fromSeconds(e-r)},subtractDateTz:function(t){var e=this.toUnixTime(),r=t.toUnixTime();return ICAL.Duration.fromSeconds(e-r)},compare:function(t){var e=this.toUnixTime(),r=t.toUnixTime();return e>r?1:r>e?-1:0},compareDateOnlyTz:function(t,e){function r(t){return ICAL.Time._cmp_attr(n,i,t)}var n=this.convertToZone(e),i=t.convertToZone(e),a=0;return 0!=(a=r("year"))?a:0!=(a=r("month"))?a:a=r("day")},convertToZone:function(t){var e=this.clone(),r=this.zone.tzid==t.tzid;return this.isDate||r||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(){this._time.isDate;return 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,r,n,i){var a,s,o,u,h,c,l,d=0,f=0,m=i||this._time;if(m.isDate||(o=m.second+n,m.second=o%60,a=ICAL.helpers.trunc(o/60),m.second<0&&(m.second+=60,a--),u=m.minute+r+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++,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"],r=Object.create(null),n=0,i=e.length;n12?n:(n=r[t],2==t&&(n+=ICAL.Time.isLeapYear(e)),n)},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 r=e,n=t,i=new ICAL.Time;i.auto_normalize=!1;var a=ICAL.Time.isLeapYear(r)?1:0;if(n<1)return r--,a=ICAL.Time.isLeapYear(r)?1:0,n+=ICAL.Time.daysInYearPassedMonth[a][12],ICAL.Time.fromDayOfYear(n,r);if(n>ICAL.Time.daysInYearPassedMonth[a][12])return a=ICAL.Time.isLeapYear(r)?1:0,n-=ICAL.Time.daysInYearPassedMonth[a][12],r++,ICAL.Time.fromDayOfYear(n,r);i.year=r,i.isDate=!0;for(var s=11;s>=0;s--)if(n>ICAL.Time.daysInYearPassedMonth[a][s]){i.month=s+1,i.day=n-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 r;return t[19]&&"Z"===t[19]?r="Z":e&&(r=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:r})},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 r=ICAL.Time.fromData({year:t,month:1,day:1,isDate:!0}),n=r.dayOfWeek(),i=e||ICAL.Time.DEFAULT_WEEK_START;return n>ICAL.Time.THURSDAY&&(r.day+=7),i>ICAL.Time.THURSDAY&&(r.day-=7),r.day-=n-i,r},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,r){return t[r]>e[r]?1:t[r]4?d?r(u,1,2):r(u,3,2):null,second:4==c?r(u,2,2):6==c?r(u,4,2):8==c?r(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,r,n){var i=n;if("+"===n[0]&&(i=n.substr(1)),i=ICAL.helpers.strictParseInt(i),void 0!==e&&n '+e);if(void 0!==r&&n>r)throw new Error(t+': invalid value "'+n+'" 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},r={};for(var n in e)e.hasOwnProperty(n)&&(r[e[n]]=n);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 r=t.toUpperCase();r in this.parts?this.parts[r].push(e):this.parts[r]=[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 r,n=this.iterator(t);do{r=n.next()}while(r&&r.compare(e)<=0);return r&&e.zone&&(r.zone=e.zone),r},fromData:function(t){for(var e in t){var r=e.toUpperCase();r in u?Array.isArray(t[e])?this.parts[r]=t[e]:this.parts[r]=[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 r=this.parts[e];Array.isArray(r)&&1==r.length?t[e.toLowerCase()]=r[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 r[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,r){if(-1===s.indexOf(t))throw new Error('invalid frequency "'+t+'" expected: "'+s.join(", ")+'"');e.freq=t},COUNT:function(t,e,r){e.count=ICAL.helpers.strictParseInt(t)},INTERVAL:function(t,e,r){e.interval=ICAL.helpers.strictParseInt(t),e.interval<1&&(e.interval=1)},UNTIL:function(t,e,r){t.length>10?e.until=ICAL.design.icalendar.value["date-time"].fromICAL(t):e.until=ICAL.design.icalendar.value.date.fromICAL(t),r||(e.until=ICAL.Time.fromString(e.until))},WKST:function(t,e,r){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 r=Object.create(null),n=t.split(";"),i=n.length,a=0;a=0||r<0)&&(this.last.day+=r)}else{var n=ICAL.Recur.numericDayToIcalDay(this.dtstart.dayOfWeek());t.BYDAY=[n]}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&&this.validate_bysetpos())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},validate_bysetpos:function(){if(!this.has_by_data("BYSETPOS"))return!0;var t=this.rule.toJSON();delete t.bysetpos,delete t.count;var e,r=ICAL.Recur.fromData(t).iterator(this.dtstart),n=[],i=r.next();if(null==i)return!1;if("YEARLY"==this.rule.freq)e=i.endOfYear();else if("MONTHLY"==this.rule.freq)e=i.endOfMonth();else{if("WEEK"!=this.rule.freq)return!0;e=i.endOfWeek()}for(n.push(i.clone());(i=r.next())&&!(e.compare(i)<0);)n.push(i.clone());for(var a=!1,s=0;si)){if(n<0)n=i+(n+1);else if(0===n)continue;-1===a.indexOf(n)&&a.push(n)}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),n=l.normalizeByMonthDayRules(l.last.year,l.last.month,l.by_data.BYMONTHDAY),a=n.length;n[u]<=d&&(!t||n[u]!=d)&&us)r();else{var m=n[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 r=this.by_data.BYDAY[this.by_indices.BYDAY],n=this.ruleDayOfWeek(r)[1];(n-=this.rule.wkst)<0&&(n+=7),e.year=this.last.year,e.month=this.last.month,e.day=this.last.day;var i=e.startDoyWeek(this.rule.wkst);if(!(n+i<1)||t){var a=ICAL.Time.fromDayOfYear(i+n,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 r=ICAL.Time.fromDayOfYear(t,e);this.last.day=r.day,this.last.month=r.month},ruleDayOfWeek:function(t){var e=t.match(/([+-]?[0-9])?(MO|TU|WE|TH|FR|SA|SU)/);if(e){var r=parseInt(e[1]||0,10);return t=ICAL.Recur.icalDayToNumericDay(e[2]),[r,t]}return[0,0]},next_generic:function(t,e,r,n,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[r]=u[this.by_indices[t]]}else s&&this["increment_"+r](this.rule.interval);return a&&o&&s&&this["increment_"+n](1),o},increment_monthday:function(t){for(var e=0;er&&(this.last.day-=r,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,r,n){this.last[e]+=t;var i=ICAL.helpers.trunc(this.last[e]/r);this.last[e]%=r,0!=i&&this["increment_"+n](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 r={},n=["BYDAY","BYWEEKNO","BYMONTHDAY","BYMONTH","BYYEARDAY"];for(var i in n)if(n.hasOwnProperty(i)){var a=n[i];a in this.rule.parts&&(r[a]=this.rule.parts[a])}if("BYMONTH"in r&&"BYWEEKNO"in r){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 r&&"BYMONTHDAY"in r){k=this.expand_by_day(t);for(var P in k)if(k.hasOwnProperty(P)){var Y=k[P],M=ICAL.Time.fromDayOfYear(Y,t);this.by_data.BYMONTHDAY.indexOf(M.day)>=0&&this.days.push(Y)}}else if(3==d&&"BYDAY"in r&&"BYMONTHDAY"in r&&"BYMONTH"in r){k=this.expand_by_day(t);for(var P in k)if(k.hasOwnProperty(P)){var Y=k[P],M=ICAL.Time.fromDayOfYear(Y,t);this.by_data.BYMONTH.indexOf(M.month)>=0&&this.by_data.BYMONTHDAY.indexOf(M.day)>=0&&this.days.push(Y)}}else if(2==d&&"BYDAY"in r&&"BYWEEKNO"in r){var k=this.expand_by_day(t);for(var P in k)if(k.hasOwnProperty(P)){var Y=k[P],U=(M=ICAL.Time.fromDayOfYear(Y,t)).weekNumber(this.rule.wkst);this.by_data.BYWEEKNO.indexOf(U)&&this.days.push(Y)}}else 3==d&&"BYDAY"in r&&"BYWEEKNO"in r&&"BYMONTHDAY"in r||(this.days=1==d&&"BYYEARDAY"in r?this.days.concat(this.by_data.BYYEARDAY):[]);return 0},expand_by_day:function(t){var e=[],r=this.last.clone();r.year=t,r.month=1,r.day=1,r.isDate=!0;var n=r.dayOfWeek();r.month=12,r.day=31,r.isDate=!0;var i=r.dayOfWeek(),a=r.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-n)%7+1;l<=a;l+=7)e.push(l);else if(h>0){var d;d=c>=n?c-n+1:c-n+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 r=this.by_data.BYDAY[e],n=this.ruleDayOfWeek(r),i=n[0],a=n[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 r=0;ra){var s=t[r];t[r]=t[n],t[n]=s}}},check_contract_restriction:function(e,r){var n=t._indexMap[e],i=t._expandMap[this.rule.freq][n],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]==r){a=!0;break}}else a=!0;return a},check_contracting_rules:function(){var t=this.last.dayOfWeek(),e=this.last.weekNumber(this.rule.wkst),r=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",r)},setup_defaults:function(e,r,n){var i=t._indexMap[e];return t._expandMap[this.rule.freq][i]!=t.CONTRACT&&(e in this.by_data||(this.by_data[e]=[n]),this.rule.freq!=r)?this.by_data[e][0]:n},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 r(t){return t.hasProperty("rdate")||t.hasProperty("rrule")||t.hasProperty("recurrence-id")}function n(t){this.ruleDates=[],this.exDates=[],this.fromData(t)}return n.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 r=ICAL.helpers.formatClassType(e.dtstart,ICAL.Time);if(!r)throw new Error(".dtstart (ICAL.Time) must be given");if(this.dtstart=r,e.component)this._init(e.component);else{if(this.last=t(e.last)||r.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,r,n=0;;){if(n++>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||((r=this.exDate.compare(this.last))<0&&this._nextExDay(),0!==r))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,r){for(var n,i=[],a=t.getAllProperties(r),s=a.length,o=0;o0)&&(n=e);return n}},n}(),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 r=t.recurrenceId.toString();if(this.exceptions[r]=t,t.modifiesFuture()){var n=[t.recurrenceId.toUnixTime(),r],i=ICAL.helpers.binsearchInsert(this.rangeExceptions,n,e);this.rangeExceptions.splice(i,0,n)}},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 r=t.toUnixTime(),n=ICAL.helpers.binsearchInsert(this.rangeExceptions,[r],e);if((n-=1)<0)return null;var i=this.rangeExceptions[n];return r= 0) { + if (this.occurrence_number == 0 && (this.last.compare(this.dtstart) >= 0 && this.validate_bysetpos())) { // First of all, give the instance that was initialized this.occurrence_number++; return this.last; @@ -460,6 +460,51 @@ ICAL.RecurIterator = (function() { return end_of_data; }, + /* + * Checks if the computed last date is valid for given bysetpos rule + */ + validate_bysetpos: function () { + if (!this.has_by_data("BYSETPOS")) { + return true; + } + + var currentJson = this.rule.toJSON(); + delete currentJson.bysetpos; + delete currentJson.count; + var recurWithoutBysetPos = ICAL.Recur.fromData(currentJson); + var iterator = recurWithoutBysetPos.iterator(this.dtstart); + var datesList = []; + var endDate; + var date = iterator.next(); + if(date == null) { + return false; + } + if(this.rule.freq == "YEARLY") { + endDate = date.endOfYear(); + } else if(this.rule.freq == "MONTHLY") { + endDate = date.endOfMonth(); + } else if(this.rule.freq == "WEEK") { + endDate = date.endOfWeek(); + } else { + return true; + } + datesList.push(date.clone()); + while(date = iterator.next()) { + if(endDate.compare(date) < 0) { + break; + } + datesList.push(date.clone()); + } + + var isValidBysetPos = false; + for(var idx = 0; idx < datesList.length; idx++) { + if(this.last.compare(datesList[idx]) == 0) { + isValidBysetPos = this.check_set_position(idx + 1) || this.check_set_position(idx - datesList.length); + } + } + return isValidBysetPos; + }, + /** * Normalize each by day rule for a given year/month. * Takes into account ordering and negative rules diff --git a/test/recur_iterator_test.js b/test/recur_iterator_test.js index 46d62315..7d2cb98c 100644 --- a/test/recur_iterator_test.js +++ b/test/recur_iterator_test.js @@ -217,12 +217,10 @@ suite('recur_iterator', function() { max = options.dates.length; } - assert.equal(recur.isFinite(), options.byCount || options.until || false); - assert.equal(recur.isByCount(), options.byCount || false); - while (inc++ < max && (next = iterator.next())) { dates.push(next.toString()); } + assert.deepEqual(dates, options.dates || []); }); } @@ -984,8 +982,377 @@ suite('recur_iterator', function() { ] }); - /* - * Leap-year test for February 29th + //DAILY TESTS + + testRRULE('FREQ=DAILY;INTERVAL=2;COUNT=3', { + dtStart: '2013-01-01', + byCount: true, + dates: [ + '2013-01-01', + '2013-01-03', + '2013-01-05' + ] + }); + + testRRULE('FREQ=DAILY;INTERVAL=321;COUNT=3', { + dtStart: '2013-01-01', + byCount: true, + dates: [ + '2013-01-01', + '2013-11-18', + '2014-10-05' + ] + }); + + testRRULE('FREQ=DAILY;INTERVAL=366', { + dtStart: '2013-01-01', + dates: [ + '2013-01-01', + '2014-01-02', + '2015-01-03', + '2016-01-04' + ] + }); + + testRRULE('FREQ=DAILY;INTERVAL=366;UNTIL=2016-01-04', { + dtStart: '2013-01-01', + until: true, + dates: [ + '2013-01-01', + '2014-01-02', + '2015-01-03', + '2016-01-04' + ] + }); + + testRRULE('FREQ=DAILY;INTERVAL=1;UNTIL=2016-01-01', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-01' + ] + }); + + testRRULE('FREQ=DAILY;INTERVAL=1;UNTIL=2016-01-02', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-01', + '2016-01-02' + ] + }); + + //Weekly Tests + // 2016-01-01 - Friday + + // This can be confusing - If StartDate satisifies with the rule, first instance (startdate) is included, and the next is not. (Alternate) + // If startDate doesn't satisfy with rule, first instance is omitted, next is added, and Alternate ones work + testRRULE('FREQ=WEEKLY;INTERVAL=2;BYDAY=SU;UNTIL=2016-01-10', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-10' + ] + }); + + testRRULE('FREQ=WEEKLY;INTERVAL=2;BYDAY=SU;UNTIL=2016-03-01', { + dtStart: '2016-01-03', + until: true, + dates: [ + '2016-01-03', + '2016-01-17', + '2016-01-31', + "2016-02-14", + "2016-02-28" + ] + }); + + + testRRULE('FREQ=WEEKLY;INTERVAL=2;BYDAY=SU;UNTIL=2016-01-03', { + dtStart: '2016-01-03', + until: true, + dates: [ + '2016-01-03' + ] + }); + + testRRULE('FREQ=WEEKLY;INTERVAL=2;BYDAY=FR;COUNT=2', { + dtStart: '2016-01-01', + dates: [ + '2016-01-01', + '2016-01-15', + ] + }); + + testRRULE('FREQ=WEEKLY;INTERVAL=2;BYDAY=SU;COUNT=1', { + dtStart: '2016-01-01', + dates: [ + '2016-01-10' + ] + }); + + testRRULE('FREQ=WEEKLY;INTERVAL=1;BYDAY=SU,MO,TU,WE,TH,FR,SA;UNTIL=2016-01-07', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-01', + '2016-01-02', + '2016-01-03', + '2016-01-04', + '2016-01-05', + '2016-01-06', + '2016-01-07' + ] + }); + + testRRULE('FREQ=WEEKLY;INTERVAL=2;BYDAY=FR,SA;COUNT=3', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-01', + '2016-01-02', + '2016-01-15' + ] + }); + + testRRULE('FREQ=WEEKLY;INTERVAL=53;BYDAY=FR,SA;COUNT=3', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-01', + '2016-01-02', + '2017-01-06' + ] + }); + + //Monthly Tests + testRRULE('FREQ=MONTHLY;BYMONTHDAY=1,2,3;INTERVAL=1;COUNT=7', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-01', + '2016-01-02', + '2016-01-03', + '2016-02-01', + '2016-02-02', + '2016-02-03', + '2016-03-01', + ] + }); + + testRRULE('FREQ=MONTHLY;BYMONTHDAY=1,3;INTERVAL=2;COUNT=3', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-01', + '2016-01-03', + '2016-03-01', + ] + }); + + testRRULE('FREQ=MONTHLY;BYMONTHDAY=3,4;INTERVAL=2;COUNT=3', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-03', + '2016-01-04', + '2016-03-03', + ] + }); + + testRRULE('FREQ=MONTHLY;BYMONTHDAY=3,4;INTERVAL=2;UNTIL=2016-03-03', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-03', + '2016-01-04', + '2016-03-03', + ] + }); + + testRRULE('FREQ=MONTHLY;BYMONTHDAY=31;INTERVAL=1;UNTIL=2016-12-31', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-31', + '2016-03-31', + '2016-05-31', + '2016-07-31', + '2016-08-31', + '2016-10-31', + '2016-12-31', + ] + }); + + testRRULE('FREQ=MONTHLY;BYMONTHDAY=29;INTERVAL=1;UNTIL=2016-06-30', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-29', + '2016-02-29', + '2016-03-29', + '2016-04-29', + '2016-05-29', + '2016-06-29', + ] + }); + + // Failing. https://github.com/mozilla-comm/ical.js/issues/328 + // First date is counted here as valid. It should not be + testRRULE('FREQ=MONTHLY;BYSETPOS=-1;BYDAY=SU,MO,TU,WE,TH,FR,SA;INTERVAL=1;COUNT=3', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-31', + '2016-02-29', + '2016-03-31', + ] + }); + + // Failing. Returns ["2016-01-01","2016-01-02", "2016-02-02"] + testRRULE('FREQ=MONTHLY;BYSETPOS=2;BYDAY=SU,MO,TU,WE,TH,FR,SA;INTERVAL=1;COUNT=3', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-02', + '2016-02-02', + '2016-03-02', + ] + }); + + // Failing + // Takes the first sunday as correct and returns ["2016-01-03", "2016-01-24", "2016-02-28"] + testRRULE('FREQ=MONTHLY;BYSETPOS=4;BYDAY=SU;INTERVAL=1;COUNT=3', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-24', + '2016-02-28', + '2016-03-27', + ] + }); + + testRRULE('FREQ=MONTHLY;BYSETPOS=1;BYDAY=SU;INTERVAL=1;COUNT=3', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-03', + '2016-02-07', + '2016-03-06', + ] + }); + + testRRULE('FREQ=MONTHLY;BYSETPOS=1;BYDAY=SU;INTERVAL=1;UNTIL=2016-03-06', { + dtStart: '2016-01-01', + until: true, + dates: [ + '2016-01-03', + '2016-02-07', + '2016-03-06', + ] + }); + + //YEARLY TESTS + + testRRULE('FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=21;COUNT=3', { + dtStart: '2016-01-01', + dates: [ + '2016-02-21', + '2017-02-21', + '2018-02-21', + ] + }); + + testRRULE('FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=21;UNTIL=2018-02-20', { + dtStart: '2016-01-01', + dates: [ + '2016-02-21', + '2017-02-21', + ] + }); + + testRRULE('FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=21;UNTIL=2018-02-21', { + dtStart: '2016-01-01', + dates: [ + '2016-02-21', + '2017-02-21', + '2018-02-21' + ] + }); + + testRRULE('FREQ=YEARLY;BYDAY=SU;BYSETPOS=1;BYMONTH=1;COUNT=3', { + dtStart: '2016-01-01', + dates: [ + '2016-01-03', + '2017-01-01', + '2018-01-07' + ] + }); + + testRRULE('FREQ=YEARLY;BYDAY=SA;BYSETPOS=-1;BYMONTH=3;COUNT=3', { + dtStart: '2016-01-01', + dates: [ + '2016-03-26', + '2017-03-25', + '2018-03-31' + ] + }); + + testRRULE('FREQ=YEARLY;BYDAY=SA;BYSETPOS=-1;BYMONTH=3;COUNT=3;INTERVAL=2', { + dtStart: '2016-01-01', + dates: [ + '2016-03-26', + '2018-03-31', + '2020-03-28', + ] + }); + + testRRULE('FREQ=YEARLY;BYDAY=SU;BYSETPOS=-1;BYMONTH=3;COUNT=3;INTERVAL=2', { + dtStart: '2016-03-27', + dates: [ + '2016-03-27', + '2018-03-25', + '2020-03-29', + ] + }); + + testRRULE('FREQ=YEARLY;BYDAY=SU;BYSETPOS=-1;BYMONTH=3;INTERVAL=2;UNTIL=2020-03-29', { + dtStart: '2016-03-27', + dates: [ + '2016-03-27', + '2018-03-25', + '2020-03-29', + ] + }); + + + //This test fails. Rrule doesn't work for leap year + // Returns ["2016-02-01", "2016-02-21", "2016-03-02", "2017-02-01", "2017-02-21", "2017-03-03"] + // testRRULE('FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=1,21,31;COUNT=6', { + // dtStart: '2016-01-01', + // dates: [ + // '2016-02-01', + // '2016-02-21', + // '2017-02-01', + // '2017-02-21', + // '2018-02-01', + // '2018-02-21', + // ] + // }); + + //This test fails. Doesn't work for leap year + // testRRULE('FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=29;COUNT=3', { + // dtStart: '2013-01-01', + // dates: [ + // '2016-02-29', + // '2020-02-29', + // '2024-02-29', + // ] + // }); + + + /* + * Leap-year test for February 29th * * See https://github.com/mozilla-comm/ical.js/issues/91 * for details From 39cda0725a03077194024298879c8924e6a6c260 Mon Sep 17 00:00:00 2001 From: Kalyanasundaram Nachiappan Date: Fri, 21 Jul 2017 17:07:05 -0700 Subject: [PATCH 2/3] Update tests --- test/recur_iterator_test.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/recur_iterator_test.js b/test/recur_iterator_test.js index 7d2cb98c..bde5e709 100644 --- a/test/recur_iterator_test.js +++ b/test/recur_iterator_test.js @@ -1014,7 +1014,7 @@ suite('recur_iterator', function() { ] }); - testRRULE('FREQ=DAILY;INTERVAL=366;UNTIL=2016-01-04', { + testRRULE('FREQ=DAILY;INTERVAL=366;UNTIL=20160104', { dtStart: '2013-01-01', until: true, dates: [ @@ -1025,7 +1025,7 @@ suite('recur_iterator', function() { ] }); - testRRULE('FREQ=DAILY;INTERVAL=1;UNTIL=2016-01-01', { + testRRULE('FREQ=DAILY;INTERVAL=1;UNTIL=20160101', { dtStart: '2016-01-01', until: true, dates: [ @@ -1033,7 +1033,7 @@ suite('recur_iterator', function() { ] }); - testRRULE('FREQ=DAILY;INTERVAL=1;UNTIL=2016-01-02', { + testRRULE('FREQ=DAILY;INTERVAL=1;UNTIL=20160102', { dtStart: '2016-01-01', until: true, dates: [ @@ -1047,7 +1047,7 @@ suite('recur_iterator', function() { // This can be confusing - If StartDate satisifies with the rule, first instance (startdate) is included, and the next is not. (Alternate) // If startDate doesn't satisfy with rule, first instance is omitted, next is added, and Alternate ones work - testRRULE('FREQ=WEEKLY;INTERVAL=2;BYDAY=SU;UNTIL=2016-01-10', { + testRRULE('FREQ=WEEKLY;INTERVAL=2;BYDAY=SU;UNTIL=20160110', { dtStart: '2016-01-01', until: true, dates: [ @@ -1055,7 +1055,7 @@ suite('recur_iterator', function() { ] }); - testRRULE('FREQ=WEEKLY;INTERVAL=2;BYDAY=SU;UNTIL=2016-03-01', { + testRRULE('FREQ=WEEKLY;INTERVAL=2;BYDAY=SU;UNTIL=20160301', { dtStart: '2016-01-03', until: true, dates: [ @@ -1068,7 +1068,7 @@ suite('recur_iterator', function() { }); - testRRULE('FREQ=WEEKLY;INTERVAL=2;BYDAY=SU;UNTIL=2016-01-03', { + testRRULE('FREQ=WEEKLY;INTERVAL=2;BYDAY=SU;UNTIL=20160103', { dtStart: '2016-01-03', until: true, dates: [ @@ -1091,7 +1091,7 @@ suite('recur_iterator', function() { ] }); - testRRULE('FREQ=WEEKLY;INTERVAL=1;BYDAY=SU,MO,TU,WE,TH,FR,SA;UNTIL=2016-01-07', { + testRRULE('FREQ=WEEKLY;INTERVAL=1;BYDAY=SU,MO,TU,WE,TH,FR,SA;UNTIL=20160107', { dtStart: '2016-01-01', until: true, dates: [ @@ -1160,7 +1160,7 @@ suite('recur_iterator', function() { ] }); - testRRULE('FREQ=MONTHLY;BYMONTHDAY=3,4;INTERVAL=2;UNTIL=2016-03-03', { + testRRULE('FREQ=MONTHLY;BYMONTHDAY=3,4;INTERVAL=2;UNTIL=20160303', { dtStart: '2016-01-01', until: true, dates: [ @@ -1170,7 +1170,7 @@ suite('recur_iterator', function() { ] }); - testRRULE('FREQ=MONTHLY;BYMONTHDAY=31;INTERVAL=1;UNTIL=2016-12-31', { + testRRULE('FREQ=MONTHLY;BYMONTHDAY=31;INTERVAL=1;UNTIL=20161231', { dtStart: '2016-01-01', until: true, dates: [ @@ -1184,7 +1184,7 @@ suite('recur_iterator', function() { ] }); - testRRULE('FREQ=MONTHLY;BYMONTHDAY=29;INTERVAL=1;UNTIL=2016-06-30', { + testRRULE('FREQ=MONTHLY;BYMONTHDAY=29;INTERVAL=1;UNTIL=20160630', { dtStart: '2016-01-01', until: true, dates: [ @@ -1242,7 +1242,7 @@ suite('recur_iterator', function() { ] }); - testRRULE('FREQ=MONTHLY;BYSETPOS=1;BYDAY=SU;INTERVAL=1;UNTIL=2016-03-06', { + testRRULE('FREQ=MONTHLY;BYSETPOS=1;BYDAY=SU;INTERVAL=1;UNTIL=20160306', { dtStart: '2016-01-01', until: true, dates: [ @@ -1263,7 +1263,7 @@ suite('recur_iterator', function() { ] }); - testRRULE('FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=21;UNTIL=2018-02-20', { + testRRULE('FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=21;UNTIL=20180220', { dtStart: '2016-01-01', dates: [ '2016-02-21', @@ -1271,7 +1271,7 @@ suite('recur_iterator', function() { ] }); - testRRULE('FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=21;UNTIL=2018-02-21', { + testRRULE('FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=21;UNTIL=20180221', { dtStart: '2016-01-01', dates: [ '2016-02-21', @@ -1316,7 +1316,7 @@ suite('recur_iterator', function() { ] }); - testRRULE('FREQ=YEARLY;BYDAY=SU;BYSETPOS=-1;BYMONTH=3;INTERVAL=2;UNTIL=2020-03-29', { + testRRULE('FREQ=YEARLY;BYDAY=SU;BYSETPOS=-1;BYMONTH=3;INTERVAL=2;UNTIL=20200329', { dtStart: '2016-03-27', dates: [ '2016-03-27', From b0b503ede27bdf452ff1312fb95bbb8b5a7417c2 Mon Sep 17 00:00:00 2001 From: Kalyanasundaram Nachiappan Date: Tue, 25 Jul 2017 13:37:44 -0700 Subject: [PATCH 3/3] Change based on start of frequency --- lib/ical/recur_iterator.js | 23 +++++++++++++---------- test/recur_iterator_test.js | 16 +++++++++++----- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/ical/recur_iterator.js b/lib/ical/recur_iterator.js index ac906ba0..b933b4db 100644 --- a/lib/ical/recur_iterator.js +++ b/lib/ical/recur_iterator.js @@ -472,22 +472,25 @@ ICAL.RecurIterator = (function() { delete currentJson.bysetpos; delete currentJson.count; var recurWithoutBysetPos = ICAL.Recur.fromData(currentJson); - var iterator = recurWithoutBysetPos.iterator(this.dtstart); - var datesList = []; - var endDate; - var date = iterator.next(); - if(date == null) { - return false; - } + var startDate,endDate; if(this.rule.freq == "YEARLY") { - endDate = date.endOfYear(); + startDate = this.dtstart.clone().startOfYear(); + endDate = this.dtstart.clone().endOfYear(); } else if(this.rule.freq == "MONTHLY") { - endDate = date.endOfMonth(); + startDate = this.dtstart.clone().startOfMonth(); + endDate = this.dtstart.clone().endOfMonth(); } else if(this.rule.freq == "WEEK") { - endDate = date.endOfWeek(); + startDate = this.dtstart.clone().startOfWeek(); + endDate = this.dtstart.clone().endOfWeek(); } else { return true; } + var iterator = recurWithoutBysetPos.iterator(startDate); + var datesList = []; + var date = iterator.next(); + if(date == null) { + return false; + } datesList.push(date.clone()); while(date = iterator.next()) { if(endDate.compare(date) < 0) { diff --git a/test/recur_iterator_test.js b/test/recur_iterator_test.js index bde5e709..244194a5 100644 --- a/test/recur_iterator_test.js +++ b/test/recur_iterator_test.js @@ -1140,6 +1140,17 @@ suite('recur_iterator', function() { ] }); + testRRULE('FREQ=MONTHLY;INTERVAL=1;BYDAY=SU;BYSETPOS=3;COUNT=3', { + dtStart: '2017-07-15', + until: true, + dates: [ + '2017-07-16', + "2017-08-20", + '2017-09-17', + ] + }); + + testRRULE('FREQ=MONTHLY;BYMONTHDAY=1,3;INTERVAL=2;COUNT=3', { dtStart: '2016-01-01', until: true, @@ -1197,8 +1208,6 @@ suite('recur_iterator', function() { ] }); - // Failing. https://github.com/mozilla-comm/ical.js/issues/328 - // First date is counted here as valid. It should not be testRRULE('FREQ=MONTHLY;BYSETPOS=-1;BYDAY=SU,MO,TU,WE,TH,FR,SA;INTERVAL=1;COUNT=3', { dtStart: '2016-01-01', until: true, @@ -1209,7 +1218,6 @@ suite('recur_iterator', function() { ] }); - // Failing. Returns ["2016-01-01","2016-01-02", "2016-02-02"] testRRULE('FREQ=MONTHLY;BYSETPOS=2;BYDAY=SU,MO,TU,WE,TH,FR,SA;INTERVAL=1;COUNT=3', { dtStart: '2016-01-01', until: true, @@ -1220,8 +1228,6 @@ suite('recur_iterator', function() { ] }); - // Failing - // Takes the first sunday as correct and returns ["2016-01-03", "2016-01-24", "2016-02-28"] testRRULE('FREQ=MONTHLY;BYSETPOS=4;BYDAY=SU;INTERVAL=1;COUNT=3', { dtStart: '2016-01-01', until: true,