ical-generator 11.1.3-develop.3 → 11.1.3-develop.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -6
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.mts +6 -2
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/calendar.ts +3 -1
- package/src/event.ts +3 -1
package/README.md
CHANGED
|
@@ -81,15 +81,24 @@ You can also pass a string which is then passed to javascript's `Date` internall
|
|
|
81
81
|
|
|
82
82
|
It is recommended to use UTC time as far as possible. `ical-generator` will output all time information as UTC time as
|
|
83
83
|
long as no time zone is defined. For day.js, a plugin is necessary for this, which is a prerequisite. If a time zone is
|
|
84
|
-
set, `ical-generator` assumes that the given time matches the time zone.
|
|
85
|
-
|
|
86
|
-
`
|
|
84
|
+
set, `ical-generator` assumes that the given time matches the time zone.
|
|
85
|
+
|
|
86
|
+
Please note that a native `Date` (or a string) has no time zone of its own. If a time zone is set, `ical-generator`
|
|
87
|
+
uses the local time of the machine it runs on (`getHours()` etc.) and labels it with the given time zone. The result
|
|
88
|
+
therefore depends on the server's time zone: `new Date('2026-07-01T09:30:00Z')` with `timezone: 'Europe/Prague'` becomes
|
|
89
|
+
`DTSTART;TZID=Europe/Prague:20260701T093000` on a server running in UTC, although 09:30 UTC is 11:30 in Prague. To get
|
|
90
|
+
the same output everywhere, pass a `TZDate`, a Luxon `DateTime`, a `moment-timezone` or a Temporal object, or do not
|
|
91
|
+
set a time zone so that the time is written as UTC.
|
|
92
|
+
|
|
93
|
+
If a time zone is used, it is also recommended to use a VTimezone generator. Such a function generates a VTimezone entry
|
|
94
|
+
and returns it. For example, `timezones-ical-library` or `@touch4it/ical-timezones` can be used for this:
|
|
87
95
|
|
|
88
96
|
#### Example with `@touch4it/ical-timezones`
|
|
89
97
|
|
|
90
98
|
```typescript
|
|
91
99
|
import { ICalCalendar } from 'ical-generator';
|
|
92
100
|
import { getVtimezoneComponent } from '@touch4it/ical-timezones';
|
|
101
|
+
import { TZDate } from '@date-fns/tz';
|
|
93
102
|
|
|
94
103
|
const cal = new ICalCalendar();
|
|
95
104
|
cal.timezone({
|
|
@@ -97,7 +106,7 @@ cal.timezone({
|
|
|
97
106
|
generator: getVtimezoneComponent,
|
|
98
107
|
});
|
|
99
108
|
cal.createEvent({
|
|
100
|
-
start: new
|
|
109
|
+
start: new TZDate(2026, 0, 15, 9, 30, 'Europe/London'), // 09:30 London time
|
|
101
110
|
timezone: 'Europe/London',
|
|
102
111
|
});
|
|
103
112
|
```
|
|
@@ -107,14 +116,15 @@ cal.createEvent({
|
|
|
107
116
|
```typescript
|
|
108
117
|
import { ICalCalendar } from 'ical-generator';
|
|
109
118
|
import { tzlib_get_ical_block } from 'timezones-ical-library';
|
|
119
|
+
import { TZDate } from '@date-fns/tz';
|
|
110
120
|
|
|
111
121
|
const cal = new ICalCalendar();
|
|
112
122
|
cal.timezone({
|
|
113
|
-
name: 'Europe/
|
|
123
|
+
name: 'Europe/London',
|
|
114
124
|
generator: (tz) => tzlib_get_ical_block(tz)[0],
|
|
115
125
|
});
|
|
116
126
|
cal.createEvent({
|
|
117
|
-
start: new
|
|
127
|
+
start: new TZDate(2026, 0, 15, 9, 30, 'Europe/London'), // 09:30 London time
|
|
118
128
|
timezone: 'Europe/London',
|
|
119
129
|
});
|
|
120
130
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
`,n=o),t+=i}return t}).join(`\r
|
|
4
4
|
`)}function d(e,t,n,r){if(e?.startsWith(`/`)&&(e=e.substr(1)),typeof t==`string`||t instanceof Date){let i=T(t)?t.withTimeZone(e):new Date(t),a=i.getUTCFullYear().toString().padStart(4,`0`)+String(i.getUTCMonth()+1).padStart(2,`0`)+i.getUTCDate().toString().padStart(2,`0`);return e&&(a=i.getFullYear().toString().padStart(2,`0`)+String(i.getMonth()+1).padStart(2,`0`)+i.getDate().toString().padStart(2,`0`)),n?a:e?(a+=`T`+i.getHours().toString().padStart(2,`0`)+i.getMinutes().toString().padStart(2,`0`)+i.getSeconds().toString().padStart(2,`0`),a):(a+=`T`+i.getUTCHours().toString().padStart(2,`0`)+i.getUTCMinutes().toString().padStart(2,`0`)+i.getUTCSeconds().toString().padStart(2,`0`)+(r?``:`Z`),a)}if(g(t)){let i=e?v(t)&&!t.tz()?t.clone().tz(e):t:r||n&&v(t)&&t.tz()?t:t.utc();return i.format(`YYYYMMDD`)+(n?``:`T`+i.format(`HHmmss`)+(r||e?``:`Z`))}if(h(t)){let i=e?t.setZone(e):r||n&&t.zone.type!==`system`?t:t.setZone(`utc`);return i.toFormat(`yyyyLLdd`)+(n?``:`T`+i.toFormat(`HHmmss`)+(r||e?``:`Z`))}if(w(t)){let i=t;return e&&(i=t.withTimeZone(e)),!e&&t.timeZoneId!==`UTC`&&(i=t.withTimeZone(`UTC`)),d(null,i.toPlainDateTime(),n,r||!!e)}if(C(t)){if(n)return t.year.toString().padStart(4,`0`)+t.month.toString().padStart(2,`0`)+t.day.toString().padStart(2,`0`);if(e){let i=t.toZonedDateTime(e);return d(e,i,n,r)}return t.year.toString().padStart(4,`0`)+t.month.toString().padStart(2,`0`)+t.day.toString().padStart(2,`0`)+`T`+t.hour.toString().padStart(2,`0`)+t.minute.toString().padStart(2,`0`)+t.second.toString().padStart(2,`0`)+(r||e?``:`Z`)}if(S(t))return t.year.toString().padStart(4,`0`)+t.month.toString().padStart(2,`0`)+t.day.toString().padStart(2,`0`)+(n?``:`T000000`+(r||e?``:`Z`));if(x(t)){let i=e||`UTC`,a=t.toZonedDateTimeISO(i);return d(e,a,n,r)}{let i=t;if(e)i=typeof t.tz==`function`?t.tz(e):t;else if(!r){if(typeof t.utc==`function`)i=t.utc();else throw Error(`Unable to convert dayjs object to UTC value: UTC plugin is not available!`)}return i.format(`YYYYMMDD`)+(n?``:`T`+i.format(`HHmmss`)+(r||e?``:`Z`))}}function f(e,t,n,r){let i=``,a=r?.floating||!1;return r?.timezone&&(i=`;TZID=`+r.timezone,a=!0),t+i+`:`+d(e,n,!1,a)}function p(e){let t=e.x.map(([e,t])=>e.toUpperCase()+`:`+c(t,!1)).join(`\r
|
|
5
5
|
`);return t.length?t+`\r
|
|
6
|
-
`:``}function m(e){return typeof e==`object`&&!!e&&!(e instanceof Date)&&!g(e)&&!h(e)&&!b(e)}function h(e){return typeof e==`object`&&!!e&&`toJSDate`in e&&typeof e.toJSDate==`function`&&!b(e)}function g(e){return e!=null&&e._isAMomentObject!=null&&!b(e)}function _(e){return typeof e==`object`&&!!e&&`asSeconds`in e&&typeof e.asSeconds==`function`}function v(e){return g(e)&&`tz`in e&&typeof e.tz==`function`}function y(e){return typeof e==`object`&&!!e&&`between`in e&&typeof e.between==`function`&&typeof e.toString==`function`}function b(e){return w(e)||C(e)||S(e)||x(e)}function x(e){return typeof e==`object`&&!!e&&!w(e)&&!C(e)&&!S(e)&&`toZonedDateTimeISO`in e&&typeof e.toZonedDateTimeISO==`function`&&!(`year`in e)&&!(`timeZoneId`in e)}function S(e){return typeof e==`object`&&!!e&&!w(e)&&!C(e)&&`toPlainDateTime`in e&&typeof e.toPlainDateTime==`function`&&`year`in e&&typeof e.year==`number`&&`month`in e&&typeof e.month==`number`&&`day`in e&&typeof e.day==`number`&&!(`hour`in e)&&!(`timeZoneId`in e)&&!(`epochSeconds`in e)}function C(e){return typeof e==`object`&&!!e&&!w(e)&&`toZonedDateTime`in e&&typeof e.toZonedDateTime==`function`&&`toPlainDate`in e&&typeof e.toPlainDate==`function`&&`year`in e&&typeof e.year==`number`&&`month`in e&&typeof e.month==`number`&&`day`in e&&typeof e.day==`number`&&`hour`in e&&typeof e.hour==`number`&&`minute`in e&&typeof e.minute==`number`&&`second`in e&&typeof e.second==`number`&&!(`timeZone`in e)}function w(e){return typeof e==`object`&&!!e&&`timeZoneId`in e&&typeof e.timeZoneId==`string`&&`toPlainDateTime`in e&&typeof e.toPlainDateTime==`function`&&`year`in e&&typeof e.year==`number`&&`month`in e&&typeof e.month==`number`&&`day`in e&&typeof e.day==`number`&&`hour`in e&&typeof e.hour==`number`&&`minute`in e&&typeof e.minute==`number`&&`second`in e&&typeof e.second==`number`}function T(e){return e instanceof Date&&`internal`in e&&e.internal instanceof Date&&`withTimeZone`in e&&typeof e.withTimeZone==`function`&&`tzComponents`in e&&typeof e.tzComponents==`function`}function E(e){let t=l(e);return/[,:;]/.test(t)?`"`+t+`"`:t}function D(e){if(typeof e==`string`||e instanceof Date)return new Date(e);if(w(e)){let t=e.toInstant();return new Date(t.epochMilliseconds)}return C(e)?new Date(Date.UTC(e.year,e.month-1,e.day,e.hour,e.minute,e.second)):S(e)?new Date(Date.UTC(e.year,e.month-1,e.day)):x(e)?new Date(e.epochMilliseconds):h(e)?e.toJSDate():e.toDate()}function O(e){let t=``;return e<0&&(t=`-`,e*=-1),t+=`P`,e>=86400&&(t+=Math.floor(e/86400)+`D`,e%=86400),!e&&t.length>1
|
|
6
|
+
`:``}function m(e){return typeof e==`object`&&!!e&&!(e instanceof Date)&&!g(e)&&!h(e)&&!b(e)}function h(e){return typeof e==`object`&&!!e&&`toJSDate`in e&&typeof e.toJSDate==`function`&&!b(e)}function g(e){return e!=null&&e._isAMomentObject!=null&&!b(e)}function _(e){return typeof e==`object`&&!!e&&`asSeconds`in e&&typeof e.asSeconds==`function`}function v(e){return g(e)&&`tz`in e&&typeof e.tz==`function`}function y(e){return typeof e==`object`&&!!e&&`between`in e&&typeof e.between==`function`&&typeof e.toString==`function`}function b(e){return w(e)||C(e)||S(e)||x(e)}function x(e){return typeof e==`object`&&!!e&&!w(e)&&!C(e)&&!S(e)&&`toZonedDateTimeISO`in e&&typeof e.toZonedDateTimeISO==`function`&&!(`year`in e)&&!(`timeZoneId`in e)}function S(e){return typeof e==`object`&&!!e&&!w(e)&&!C(e)&&`toPlainDateTime`in e&&typeof e.toPlainDateTime==`function`&&`year`in e&&typeof e.year==`number`&&`month`in e&&typeof e.month==`number`&&`day`in e&&typeof e.day==`number`&&!(`hour`in e)&&!(`timeZoneId`in e)&&!(`epochSeconds`in e)}function C(e){return typeof e==`object`&&!!e&&!w(e)&&`toZonedDateTime`in e&&typeof e.toZonedDateTime==`function`&&`toPlainDate`in e&&typeof e.toPlainDate==`function`&&`year`in e&&typeof e.year==`number`&&`month`in e&&typeof e.month==`number`&&`day`in e&&typeof e.day==`number`&&`hour`in e&&typeof e.hour==`number`&&`minute`in e&&typeof e.minute==`number`&&`second`in e&&typeof e.second==`number`&&!(`timeZone`in e)}function w(e){return typeof e==`object`&&!!e&&`timeZoneId`in e&&typeof e.timeZoneId==`string`&&`toPlainDateTime`in e&&typeof e.toPlainDateTime==`function`&&`year`in e&&typeof e.year==`number`&&`month`in e&&typeof e.month==`number`&&`day`in e&&typeof e.day==`number`&&`hour`in e&&typeof e.hour==`number`&&`minute`in e&&typeof e.minute==`number`&&`second`in e&&typeof e.second==`number`}function T(e){return e instanceof Date&&`internal`in e&&e.internal instanceof Date&&`withTimeZone`in e&&typeof e.withTimeZone==`function`&&`tzComponents`in e&&typeof e.tzComponents==`function`}function E(e){let t=l(e);return/[,:;]/.test(t)?`"`+t+`"`:t}function D(e){if(typeof e==`string`||e instanceof Date)return new Date(e);if(w(e)){let t=e.toInstant();return new Date(t.epochMilliseconds)}return C(e)?new Date(Date.UTC(e.year,e.month-1,e.day,e.hour,e.minute,e.second)):S(e)?new Date(Date.UTC(e.year,e.month-1,e.day)):x(e)?new Date(e.epochMilliseconds):h(e)?e.toJSDate():e.toDate()}function O(e){let t=``;return e<0&&(t=`-`,e*=-1),t+=`P`,e>=86400&&(t+=Math.floor(e/86400)+`D`,e%=86400),!e&&t.length>1||(t+=`T`,e>=3600&&(t+=Math.floor(e/3600)+`H`,e%=3600),e>=60&&(t+=Math.floor(e/60)+`M`,e%=60),e>0?t+=e+`S`:t.length<=2&&(t+=`0S`)),t}function k(e){return e?typeof e==`string`?e:w(e)?k(e.withTimeZone(`UTC`).toPlainDateTime()):(b(e),e.toJSON()):null}function A(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>127)return!1;return!0}let j=/* @__PURE__ */ function(e){return e.CHAIR=`CHAIR`,e.NON=`NON-PARTICIPANT`,e.OPT=`OPT-PARTICIPANT`,e.REQ=`REQ-PARTICIPANT`,e}({}),M=/* @__PURE__ */ function(e){return e.CLIENT=`CLIENT`,e.NONE=`NONE`,e.SERVER=`SERVER`,e}({}),N=/* @__PURE__ */ function(e){return e.ACCEPTED=`ACCEPTED`,e.DECLINED=`DECLINED`,e.DELEGATED=`DELEGATED`,e.NEEDSACTION=`NEEDS-ACTION`,e.TENTATIVE=`TENTATIVE`,e}({}),P=/* @__PURE__ */ function(e){return e.GROUP=`GROUP`,e.INDIVIDUAL=`INDIVIDUAL`,e.RESOURCE=`RESOURCE`,e.ROOM=`ROOM`,e.UNKNOWN=`UNKNOWN`,e}({});var F=class e{data;parent;constructor(e,t){if(this.data={delegatedFrom:null,delegatedTo:null,email:``,mailto:null,name:null,role:`REQ-PARTICIPANT`,rsvp:null,scheduleAgent:null,sentBy:null,status:null,type:null,x:[]},this.parent=t,!this.parent)throw Error("`event` option required!");if(!e.email)throw Error("No value for `email` in ICalAttendee given!");e.name!==void 0&&this.name(e.name),e.email!==void 0&&this.email(e.email),e.mailto!==void 0&&this.mailto(e.mailto),e.sentBy!==void 0&&this.sentBy(e.sentBy),e.status!==void 0&&this.status(e.status),e.role!==void 0&&this.role(e.role),e.rsvp!==void 0&&this.rsvp(e.rsvp),e.type!==void 0&&this.type(e.type),e.delegatedTo!==void 0&&this.delegatedTo(e.delegatedTo),e.delegatedFrom!==void 0&&this.delegatedFrom(e.delegatedFrom),e.delegatesTo&&this.delegatesTo(e.delegatesTo),e.delegatesFrom&&this.delegatesFrom(e.delegatesFrom),e.scheduleAgent!==void 0&&this.scheduleAgent(e.scheduleAgent),e.x!==void 0&&this.x(e.x)}delegatedFrom(t){return t===void 0?this.data.delegatedFrom:(t?typeof t==`string`?this.data.delegatedFrom=new e(s(`delegatedFrom`,t),this.parent):t instanceof e?this.data.delegatedFrom=t:this.data.delegatedFrom=new e(t,this.parent):this.data.delegatedFrom=null,this)}delegatedTo(t){return t===void 0?this.data.delegatedTo:t?(typeof t==`string`?this.data.delegatedTo=new e(s(`delegatedTo`,t),this.parent):t instanceof e?this.data.delegatedTo=t:this.data.delegatedTo=new e(t,this.parent),this.data.status=`DELEGATED`,this):(this.data.delegatedTo=null,this.data.status===`DELEGATED`&&(this.data.status=null),this)}delegatesFrom(t){let n=t instanceof e?t:this.parent.createAttendee(t);return this.delegatedFrom(n),n.delegatedTo(this),n}delegatesTo(t){let n=t instanceof e?t:this.parent.createAttendee(t);return this.delegatedTo(n),n.delegatedFrom(this),n}email(e){return e?(this.data.email=e,this):this.data.email}mailto(e){return e===void 0?this.data.mailto:(this.data.mailto=e||null,this)}name(e){return e===void 0?this.data.name:(this.data.name=e||null,this)}role(e){return e===void 0?this.data.role:(this.data.role=o(j,e),this)}rsvp(e){return e===void 0?this.data.rsvp:e===null?(this.data.rsvp=null,this):(this.data.rsvp=!!e,this)}scheduleAgent(e){return e===void 0?this.data.scheduleAgent:e?typeof e==`string`&&e.toUpperCase().startsWith(`X-`)?(this.data.scheduleAgent=e,this):(this.data.scheduleAgent=o(M,e),this):(this.data.scheduleAgent=null,this)}sentBy(e){return e?(this.data.sentBy=e,this):this.data.sentBy}status(e){return e===void 0?this.data.status:e?(this.data.status=o(N,e),this):(this.data.status=null,this)}toJSON(){return Object.assign({},this.data,{delegatedFrom:this.data.delegatedFrom?.email()||null,delegatedTo:this.data.delegatedTo?.email()||null,x:this.x()})}toString(){let e=`ATTENDEE`;if(!this.data.email)throw Error("No value for `email` in ICalAttendee given!");return e+=`;ROLE=`+this.data.role,this.data.type&&(e+=`;CUTYPE=`+this.data.type),this.data.status&&(e+=`;PARTSTAT=`+this.data.status),this.data.rsvp!==null&&(e+=`;RSVP=`+this.data.rsvp.toString().toUpperCase()),this.data.sentBy!==null&&(e+=`;SENT-BY="mailto:`+l(this.data.sentBy)+`"`),this.data.delegatedTo&&(e+=`;DELEGATED-TO="`+l(this.data.delegatedTo.email())+`"`),this.data.delegatedFrom&&(e+=`;DELEGATED-FROM="`+l(this.data.delegatedFrom.email())+`"`),this.data.name&&(e+=`;CN="`+l(this.data.name)+`"`),this.data.email&&this.data.mailto&&(e+=`;EMAIL=`+E(this.data.email)),this.data.scheduleAgent&&(e+=`;SCHEDULE-AGENT=`+this.data.scheduleAgent),this.data.x.length&&(e+=`;`+this.data.x.map(([e,t])=>e.toUpperCase()+`=`+E(t)).join(`;`)),e+=`:MAILTO:`+c(this.data.mailto||this.data.email,!1)+`\r
|
|
7
7
|
`,e}type(e){return e===void 0?this.data.type:e?(this.data.type=o(P,e),this):(this.data.type=null,this)}x(e,t){if(e===void 0)return i(this.data);if(typeof e==`string`&&typeof t==`string`)i(this.data,e,t);else if(typeof e==`object`)i(this.data,e);else throw Error(`Either key or value is not a string!`);return this}};let I=/* @__PURE__ */ function(e){return e.audio=`audio`,e.display=`display`,e.email=`email`,e}({});const L={end:`END`,start:`START`};var R=class{data;event;constructor(e,t){if(this.data={attach:null,attendees:[],description:null,interval:null,relatesTo:null,repeat:null,summary:null,trigger:-600,type:`display`,x:[]},this.event=t,!t)throw Error("`event` option required!");e.type!==void 0&&this.type(e.type),`trigger`in e&&e.trigger!==void 0&&this.trigger(e.trigger),`triggerBefore`in e&&e.triggerBefore!==void 0&&this.triggerBefore(e.triggerBefore),`triggerAfter`in e&&e.triggerAfter!==void 0&&this.triggerAfter(e.triggerAfter),e.repeat&&this.repeat(e.repeat),e.attach!==void 0&&this.attach(e.attach),e.description!==void 0&&this.description(e.description),e.summary!==void 0&&this.summary(e.summary),e.attendees!==void 0&&this.attendees(e.attendees),e.x!==void 0&&this.x(e.x)}attach(e){if(e===void 0)return this.data.attach;if(!e)return this.data.attach=null,this;let t;if(typeof e==`string`)t={mime:null,uri:e};else if(typeof e==`object`)t={mime:e.mime||null,uri:e.uri};else throw Error("`attachment` needs to be a valid formed string or an object. See https://sebbo2002.github.io/ical-generator/develop/reference/classes/ICalAlarm.html#attach");if(!t.uri)throw Error("`attach.uri` is empty!");return this.data.attach={mime:t.mime,uri:t.uri},this}attendees(e){return e?(e.forEach(e=>this.createAttendee(e)),this):this.data.attendees}createAttendee(e){if(e instanceof F)return this.data.attendees.push(e),e;typeof e==`string`&&(e=s(`data`,e));let t=new F(e,this);return this.data.attendees.push(t),t}description(e){return e===void 0?this.data.description:e?(this.data.description=e,this):(this.data.description=null,this)}relatesTo(e){if(e===void 0)return this.data.relatesTo;if(!e)return this.data.relatesTo=null,this;if(!Object.values(L).includes(e))throw Error("`relatesTo` is not correct, must be either `START` or `END`!");return this.data.relatesTo=e,this}repeat(e){if(e===void 0)return this.data.repeat;if(!e)return this.data.repeat=null,this;if(typeof e!=`object`)throw Error("`repeat` is not correct, must be an object!");if(typeof e.times!=`number`||!isFinite(e.times))throw Error("`repeat.times` is not correct, must be numeric!");if(typeof e.interval!=`number`||!isFinite(e.interval))throw Error("`repeat.interval` is not correct, must be numeric!");return this.data.repeat=e,this}summary(e){return e===void 0?this.data.summary:e?(this.data.summary=e,this):(this.data.summary=null,this)}toJSON(){let e=this.trigger();return Object.assign({},this.data,{trigger:typeof e==`number`?e:k(e),x:this.x()})}toString(){let e=`BEGIN:VALARM\r
|
|
8
8
|
`;if(e+=`ACTION:`+this.data.type.toUpperCase()+`\r
|
|
9
9
|
`,typeof this.data.trigger==`number`&&this.data.relatesTo===null?this.data.trigger>0?e+=`TRIGGER;RELATED=END:`+O(this.data.trigger)+`\r
|