Skip to content

Commit

Permalink
Optional sequence number for iCalendar events
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Jul 2, 2023
1 parent 8e58b7c commit 583c400
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 75 deletions.
142 changes: 71 additions & 71 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/icalendar",
"version": "4.20.1",
"version": "4.21.0",
"author": "Michael J. Radwin (https://github.com/mjradwin)",
"keywords": [
"ical",
Expand Down Expand Up @@ -54,10 +54,10 @@
"@rollup/plugin-commonjs": "^25.0.2",
"@rollup/plugin-json": "^6.0.0",
"ava": "^5.3.1",
"eslint": "^8.43.0",
"eslint": "^8.44.0",
"eslint-config-google": "^0.14.0",
"jsdoc": "^4.0.2",
"jsdoc-to-markdown": "^8.0.0",
"rollup": "^3.25.3"
"rollup": "^3.26.0"
}
}
10 changes: 9 additions & 1 deletion src/icalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export class IcalEvent {
this.ev = ev;
this.options = options;
this.dtstamp = options.dtstamp || IcalEvent.makeDtstamp(new Date());
if (typeof ev.sequence === 'number') {
this.sequence = ev.sequence;
} else if (typeof options.sequence === 'number') {
this.sequence = options.sequence;
}
const timed = this.timed = Boolean(ev.eventTime);
const locale = options.locale;
let subj = shouldRenderBrief(ev) ? ev.renderBrief(locale) : ev.render(locale);
Expand Down Expand Up @@ -186,8 +191,11 @@ export class IcalEvent {
*/
getLongLines() {
if (this.lines) return this.lines;
const categoryLine = this.category ? `CATEGORIES:${this.category}` : [];
const categoryLine = this.category ? [`CATEGORIES:${this.category}`] : [];
const uid = this.ev.uid || this.getUid();
if (this.sequence) {
categoryLine.unshift(`SEQUENCE:${this.sequence}`);
}
const arr = this.lines = [
'BEGIN:VEVENT',
`DTSTAMP:${this.dtstamp}`,
Expand Down
15 changes: 15 additions & 0 deletions src/icalendar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,3 +678,18 @@ test('yerushalmi-yomi', (t) => {
];
t.deepEqual(lines, expected);
});

test('sequence', (t) => {
const ev = new TestEvent(new HDate(22, 'Iyyar', 5781));
const icalEvent = new IcalEvent(ev, {sequence: 73});
const lines = icalEvent.toString().split('\r\n').slice(0, 5);
lines[1] = 'DTSTAMP:X';
const expected = [
'BEGIN:VEVENT',
'DTSTAMP:X',
'SEQUENCE:73',
'CATEGORIES:Holiday',
'SUMMARY:Test Event',
];
t.deepEqual(lines, expected);
});

0 comments on commit 583c400

Please sign in to comment.