Skip to content

Commit

Permalink
add method to vevent (#125)
Browse files Browse the repository at this point in the history
* add method to vevent
  • Loading branch information
wodka authored Jun 8, 2021
1 parent 549b043 commit 4195ab2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
11 changes: 10 additions & 1 deletion ical.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ module.exports = {
// If this is the first time we run into this UID, just save it.
if (par[curr.uid] === undefined) {
par[curr.uid] = curr;

if (par.method) { // RFC5545, 3.2
par[curr.uid].method = par.method;
}
} else if (curr.recurrenceid === undefined) {
// If we have multiple ical entries with the same UID, it's either going to be a
// modification to a recurrence (RECURRENCE-ID), and/or a significant modification
Expand Down Expand Up @@ -475,7 +479,12 @@ module.exports = {
delete par[curr.uid].recurrenceid;
}
} else {
par[uuid()] = curr;
const id = uuid();
par[id] = curr;

if (par.method) { // RFC5545, 3.2
par[id].method = par.method;
}
}

return par;
Expand Down
2 changes: 2 additions & 0 deletions node-ical.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ declare module 'node-ical' {

export interface VEvent extends BaseComponent {
type: 'VEVENT';
method: Method;
dtstamp: DateWithTimeZone;
uid: string;
sequence: string;
Expand Down Expand Up @@ -108,4 +109,5 @@ declare module 'node-ical' {
export type DateType = 'date-time' | 'date';
export type Transparency = 'TRANSPARENT' | 'OPAQUE';
export type Class = 'PUBLIC' | 'PRIVATE' | 'CONFIDENTIAL';
export type Method = 'PUBLISH' | 'REQUEST' | 'REPLY' | 'ADD' | 'CANCEL' | 'REFRESH' | 'COUNTER' | 'DECLINECOUNTER';
}
33 changes: 33 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ vows
},
'datetype is date'(topic) {
assert.equal(topic.datetype, 'date');
},
'method is PUBLISH'(topic) {
assert.equal(topic.method, 'PUBLISH');
}
},
'event 480a': {
Expand All @@ -56,6 +59,9 @@ vows
},
'has a date only end datetime'(topic) {
assert.equal(topic.end.dateOnly, true);
},
'method is PUBLISH'(topic) {
assert.equal(topic.method, 'PUBLISH');
}
},
'event d4c8': {
Expand All @@ -69,6 +75,9 @@ vows
},
'datetype is date-time'(topic) {
assert.equal(topic.datetype, 'date-time');
},
'method is PUBLISH'(topic) {
assert.equal(topic.method, 'PUBLISH');
}
},

Expand All @@ -80,6 +89,9 @@ vows
},
'has a start datetime'(topic) {
assert.equal(topic.start, 'Next Year');
},
'method is PUBLISH'(topic) {
assert.equal(topic.method, 'PUBLISH');
}
}
},
Expand Down Expand Up @@ -163,6 +175,9 @@ vows
},
'datetype is date-time'(topic) {
assert.equal(topic.datetype, 'date-time');
},
'method is PUBLISH'(topic) {
assert.equal(topic.method, 'PUBLISH');
}
}
},
Expand Down Expand Up @@ -222,6 +237,9 @@ vows
'has a start'(topic) {
assert.equal(topic.start.tz, 'America/Phoenix');
assert.equal(topic.start.toISOString(), new Date(Date.UTC(2011, 10, 10, 2, 0, 0)).toISOString());
},
'method is PUBLISH'(topic) {
assert.equal(topic.method, 'PUBLISH');
}
}
},
Expand Down Expand Up @@ -604,6 +622,9 @@ vows
},
'starts 28 Oct 2002 @ 01:20:30 (Local Time)'(topic) {
assert.equal(topic.start.toISOString(), new Date(2002, 9, 28, 1, 20, 30).toISOString());
},
'method is REQUEST'(topic) {
assert.equal(topic.method, 'REQUEST');
}
},

Expand All @@ -621,6 +642,9 @@ vows
},
'starts 28 Oct 2002 @ 01:20:30 (UTC)'(topic) {
assert.equal(topic.start.toISOString(), '2002-10-28T01:20:30.000Z');
},
'method is REQUEST'(topic) {
assert.equal(topic.method, 'REQUEST');
}
},

Expand All @@ -638,6 +662,9 @@ vows
},
'starts 28 Oct 2002 @ 06:20:30 (UTC)'(topic) {
assert.equal(topic.start.toISOString(), '2002-10-28T06:20:30.000Z');
},
'method is REQUEST'(topic) {
assert.equal(topic.method, 'REQUEST');
}
},

Expand All @@ -655,6 +682,9 @@ vows
},
'starts 28 Oct 2002 @ 00:00:00 (Local Time)'(topic) {
assert.equal(topic.start.toISOString(), new Date(2002, 9, 28).toISOString());
},
'method is REQUEST'(topic) {
assert.equal(topic.method, 'REQUEST');
}
},

Expand All @@ -672,6 +702,9 @@ vows
},
'starts 28 Oct 2002 @ 00:00:00 (Local Time)'(topic) {
assert.equal(topic.start.toISOString(), new Date(2002, 9, 28).toISOString());
},
'method is REQUEST'(topic) {
assert.equal(topic.method, 'REQUEST');
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/test18.ics
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BEGIN:VCALENDAR
CALSCALE:GREGORIAN
X-WR-TIMEZONE;VALUE=TEXT:US/Pacific
METHOD:PUBLISH
METHOD:REQUEST
PRODID:-//Apple Computer\, Inc//iCal 1.0//EN
X-WR-CALNAME;VALUE=TEXT:Example
VERSION:2.0
Expand Down

0 comments on commit 4195ab2

Please sign in to comment.