1159cl/lib/ical.min.js

6 lines
73 KiB
JavaScript
Raw Permalink Normal View History

2024-12-06 23:38:18 +00:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* Portions Copyright (C) Philipp Kewisch */
class t{static fromString(e){return new t(e)}constructor(t){this.value=t}icaltype="binary";decodeValue(){return this._b64_decode(this.value)}setEncodedValue(t){this.value=this._b64_encode(t)}_b64_encode(t){let e,i,r,n,s,a,o,l,h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",u=0,c=0,d="",m=[];if(!t)return t;do{e=t.charCodeAt(u++),i=t.charCodeAt(u++),r=t.charCodeAt(u++),l=e<<16|i<<8|r,n=l>>18&63,s=l>>12&63,a=l>>6&63,o=63&l,m[c++]=h.charAt(n)+h.charAt(s)+h.charAt(a)+h.charAt(o)}while(u<t.length);d=m.join("");let f=t.length%3;return(f?d.slice(0,f-3):d)+"===".slice(f||3)}_b64_decode(t){let e,i,r,n,s,a,o,l,h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",u=0,c=0,d="",m=[];if(!t)return t;t+="";do{n=h.indexOf(t.charAt(u++)),s=h.indexOf(t.charAt(u++)),a=h.indexOf(t.charAt(u++)),o=h.indexOf(t.charAt(u++)),l=n<<18|s<<12|a<<6|o,e=l>>16&255,i=l>>8&255,r=255&l,m[c++]=64==a?String.fromCharCode(e):64==o?String.fromCharCode(e,i):String.fromCharCode(e,i,r)}while(u<t.length);return d=m.join(""),d}toString(){return this.value}}const e=/([PDWHMTS]{1,1})/,i=["weeks","days","hours","minutes","seconds","isNegative"];class r{static fromSeconds(t){return(new r).fromSeconds(t)}static isValueString(t){return"P"===t[0]||"P"===t[1]}static fromString(t){let i=0,s=Object.create(null),a=0;for(;-1!==(i=t.search(e));){let e=t[i],r=t.slice(0,Math.max(0,i));t=t.slice(i+1),a+=n(e,r,s)}if(a<2)throw new Error('invalid duration value: Not enough duration components in "'+t+'"');return new r(s)}static fromData(t){return new r(t)}constructor(t){this.wrappedJSObject=this,this.fromData(t)}weeks=0;days=0;hours=0;minutes=0;seconds=0;isNegative=!1;icalclass="icalduration";icaltype="duration";clone(){return r.fromData(this)}toSeconds(){let t=this.seconds+60*this.minutes+3600*this.hours+86400*this.days+604800*this.weeks;return this.isNegative?-t:t}fromSeconds(t){let e=Math.abs(t);return this.isNegative=t<0,this.days=A(e/86400),this.days%7==0?(this.weeks=this.days/7,this.days=0):this.weeks=0,e-=86400*(this.days+7*this.weeks),this.hours=A(e/3600),e-=3600*this.hours,this.minutes=A(e/60),e-=60*this.minutes,this.seconds=e,this}fromData(t){for(let e of i)this[e]=t&&e in t?t[e]:0}reset(){this.isNegative=!1,this.weeks=0,this.days=0,this.hours=0,this.minutes=0,this.seconds=0}compare(t){let e=this.toSeconds(),i=t.toSeconds();return(e>i)-(e<i)}normalize(){this.fromSeconds(this.toSeconds())}toString(){if(0==this.toSeconds())return"PT0S";{let t="";return this.isNegative&&(t+="-"),t+="P",this.weeks&&(t+=this.weeks+"W"),this.days&&(t+=this.days+"D"),(this.hours||this.minutes||this.seconds)&&(t+="T",this.hours&&(t+=this.hours+"H"),this.minutes&&(t+=this.minutes+"M"),this.seconds&&(t+=this.seconds+"S")),t}}toICALString(){return this.toString()}}function n(t,e,i){let r;switch(t){case"P":i.isNegative=!(!e||"-"!==e);break;case"D":r="days";break;case"W":r="weeks";break;case"H":r="hours";break;case"M":r="minutes";break;case"S":r="seconds";break;default:return 0}if(r){if(!e&&0!==e)throw new Error('invalid duration value: Missing number before "'+t+'"');let n=parseInt(e,10);if(f(n))throw new Error('invalid duration value: Invalid number "'+e+'" before "'+t+'"');i[r]=n}return 1}class s{static _dowCache={};static _wnCache={};static daysInMonth(t,e){let i=30;return t<1||t>12||(i=[0,31,28,31,30,31,30,31,31,30,31,30,31][t],2==t&&(i+=s.isLeapYear(e))),i}static isLeapYear(t){return t<=1752?t%4==0:t%4==0&&t%100!=0||t%400==0}static fromDayOfYear(t,e){let i=e,r=t,n=new s;n.auto_normalize=!1;let a=s.isLeapYear(i)?1:0;if(r<1)return i--,a=s.isLeapYear(i)?1:0,r+=s.daysInYearPassedMonth[a][12],s.fromDayOfYear(r,i);if(r>s.daysInYearPassedMonth[a][12])return a=s.isLeapYear(i)?1:0,r-=s.daysInYearPassedMonth[a][12],i++,s.fromDayOfYear(r,i);n.year=i,n.isDate=!0;for(let t=11;t>=0;t--)if(r>s.daysInYearPassedMonth[a][t]){n.month=t+1,n.day=r-s.daysInYearPassedMonth[a][t];break}return n.auto_normalize=!0,n}static fromStringv2(t){return new s({year:parseInt(t.slice(0,4),10),month:parseInt(t.slice(5,7),10),day:parseInt(t.slice(8,10),10),isDate:!0})}static fromDateString(t){retu