Skip to content

Commit

Permalink
fix: issue #15, rrule toText not found
Browse files Browse the repository at this point in the history
  • Loading branch information
naimo84 committed Sep 5, 2023
1 parent 2c3401c commit bd40e4f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function convertEvent(event: iCalEvent, config: Config): IKalenderEvent |
if ((config.type === "ical" && event.type === undefined) || (event.type && (!["VEVENT", "VTODO", "VALARM"].includes(event.type)))) {
return undefined;
}

/* istanbul ignore if */
if (event.type === "VTODO" && !config.includeTodo) {
return undefined;
Expand All @@ -102,6 +102,10 @@ export function convertEvent(event: iCalEvent, config: Config): IKalenderEvent |
event.duration = moment.duration(endDate.getTime() - startDate.getTime());
}

let rruleText = null;
if (event.rrule && event.rrule.toText) {
rruleText = event.rrule.toText();
}
let returnEvent: IKalenderEvent = {
date: formatDate(event, startDate, endDate, true, config),
eventStart: startDate,
Expand All @@ -114,7 +118,7 @@ export function convertEvent(event: iCalEvent, config: Config): IKalenderEvent |
location: event.location || '',
organizer: event.organizer || '',
rrule: event.rrule,
rruleText: event.rrule?.toText(),
rruleText: rruleText,
uid: uid,
isRecurring: !!recurrence || !!event.rrule,
datetype: event.type === "VTODO" ? 'todo' : 'date',
Expand Down
29 changes: 29 additions & 0 deletions test/issues_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,35 @@ describe('issues', () => {
});
});

it('#15', async () => {
return new Promise(async (resolve, reject) => {
try {
if (!process.env.CALDAV1_URL) resolve();
let ke = new KalenderEvents({
url: "./test/mocks/15.ics"
});
let events = await ke.getEvents({
now: moment('20230610').toDate(),
pastview: 1,
preview: 1,
});
expect(events).to.have.lengthOf(0)

events = await ke.getEvents({
now: moment('20230608').toDate(),
pastview: 1,
preview: 1,
});
expect(events).to.have.lengthOf(1)

resolve();
} catch (err) {
reject(err);
}
});
});


it('#9', async () => {
return new Promise(async (resolve, reject) => {
try {
Expand Down
12 changes: 12 additions & 0 deletions test/mocks/15.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
BEGIN:VEVENT
RRULE:FREQ=WEEKLY;UNTIL=20240606T070000Z;INTERVAL=1;BYDAY=MO,TH;WKST=MO
UID:1234
RECURRENCE-ID;TZID=W. Europe Standard Time:20220103T090000
SUMMARY:Test
DTSTART;TZID=W. Europe Standard Time:20220609T090000
DTEND;TZID=W. Europe Standard Time:20220609T133000
END:VEVENT
END:VCALENDAR

0 comments on commit bd40e4f

Please sign in to comment.