Skip to content

Commit

Permalink
fix(Event): Add RRULE: prefix in event.repeating() if it's not alre…
Browse files Browse the repository at this point in the history
…ady there

close #459
  • Loading branch information
sebbo2002 committed Feb 5, 2023
1 parent 011123e commit 92c2034
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1472,12 +1472,18 @@ export default class ICalEvent {

// REPEATING
if(isRRule(this.data.repeating) || typeof this.data.repeating === 'string') {
g += this.data.repeating
let repeating = this.data.repeating
.toString()
.replace(/\r\n/g, '\n')
.split('\n')
.filter(l => l && !l.startsWith('DTSTART:'))
.join('\r\n') + '\r\n';
.join('\r\n');

if(!repeating.includes('\r\n') && !repeating.startsWith('RRULE:')) {
repeating = 'RRULE:' + repeating;
}

g += repeating.trim() + '\r\n';
}
else if (this.data.repeating) {
g += 'RRULE:FREQ=' + this.data.repeating.freq;
Expand Down
9 changes: 9 additions & 0 deletions test/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,15 @@ describe('ical-generator Event', function () {
const rule = 'RRULE:FREQ=WEEKLY;INTERVAL=5;BYDAY=MO,FR;UNTIL=20130131T000000Z';
e.repeating(rule);

const result = e.repeating();
assert.deepStrictEqual(result, rule);
assert.ok(e.toString().includes('RRULE:FREQ=WEEKLY;INTERVAL=5;BYDAY=MO,FR;UNTIL=20130131T000000Z'));
});
it('should add RRULE: prefix for single line string if not already there', function () {
const e = new ICalEvent({start: new Date()}, new ICalCalendar());
const rule = 'FREQ=WEEKLY;INTERVAL=5;BYDAY=MO,FR;UNTIL=20130131T000000Z';
e.repeating(rule);

const result = e.repeating();
assert.deepStrictEqual(result, rule);
assert.ok(e.toString().includes('RRULE:FREQ=WEEKLY;INTERVAL=5;BYDAY=MO,FR;UNTIL=20130131T000000Z'));
Expand Down
55 changes: 55 additions & 0 deletions test/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,59 @@ describe('Issues', function () {
it('should generate floating repeat until value if event is a floating event');
it('should generate floating repeat exclusion dates if event is a floating event');
});

describe('Issue #459', function () {
it('event.repeating should work with `RRULE:` prefix', function () {
const calendar = ical({
events: [{
id: 'foo',
start: new Date('2020-08-13T00:00:00-05:00'),
stamp: new Date('2020-08-13T00:00:00-05:00'),
summary: 'Example Event',
repeating: 'RRULE:FREQ=MONTHLY;COUNT=3;INTERVAL=1'
}]
});

assert.strictEqual(calendar.toString(), [
'BEGIN:VCALENDAR',
'VERSION:2.0',
'PRODID:-//sebbo.net//ical-generator//EN',
'BEGIN:VEVENT',
'UID:foo',
'SEQUENCE:0',
'DTSTAMP:20200813T050000Z',
'DTSTART:20200813T050000Z',
'RRULE:FREQ=MONTHLY;COUNT=3;INTERVAL=1',
'SUMMARY:Example Event',
'END:VEVENT',
'END:VCALENDAR'
].join('\r\n'));
});
it('event.repeating should work without `RRULE:` prefix', function () {
const calendar = ical({
events: [{
id: 'foo',
start: new Date('2020-08-13T00:00:00-05:00'),
stamp: new Date('2020-08-13T00:00:00-05:00'),
summary: 'Example Event',
repeating: 'FREQ=MONTHLY;COUNT=3;INTERVAL=1'
}]
});

assert.strictEqual(calendar.toString(), [
'BEGIN:VCALENDAR',
'VERSION:2.0',
'PRODID:-//sebbo.net//ical-generator//EN',
'BEGIN:VEVENT',
'UID:foo',
'SEQUENCE:0',
'DTSTAMP:20200813T050000Z',
'DTSTART:20200813T050000Z',
'RRULE:FREQ=MONTHLY;COUNT=3;INTERVAL=1',
'SUMMARY:Example Event',
'END:VEVENT',
'END:VCALENDAR'
].join('\r\n'));
});
});
});

0 comments on commit 92c2034

Please sign in to comment.