Skip to content

Commit

Permalink
fix: Adjust repeating event calculation to include last occurrence
Browse files Browse the repository at this point in the history
- Updated untilTime calculation to set to midnight after endDate, ensuring the last event occurrence is included.
- Optimized code comments for clarity and readability.
  • Loading branch information
shfc committed Aug 13, 2024
1 parent ffa0cab commit 7711a6a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ function createCalEvent(calendar: ICalCalendar, data: { [x: string]: any }) {
const eventEnd = new Date(Date.parse(`${startDateData}T${endTime}`));

// Use this to calculate repeating times
let endDate = new Date(Date.parse(endDateData));
endDate.setDate(endDate.getDate() + 1);
appendLog(logLevels.DEBUG,`Creating event: ${eventSummary} - start: ${eventStart}; end: ${eventEnd}; enddate: ${endDate}; clsType: ${classType}`);
// The UNTIL parameter is non-inclusive, so set untilTime to midnight after the endDate to include the last event occurrence
let utilTime = new Date(new Date(endDateData).setHours(24, 0, 0, 0));
appendLog(logLevels.DEBUG,`Creating event: ${eventSummary} - start: ${eventStart}; end: ${eventEnd}; untiltime: ${utilTime}; clsType: ${classType}`);
const repeatOptions: ICalRepeatingOptions = {
freq: ICalEventRepeatingFreq.WEEKLY,
until: endDate,
until: utilTime,
};

calendar.createEvent({
Expand All @@ -60,7 +60,7 @@ function createCalEvent(calendar: ICalCalendar, data: { [x: string]: any }) {
repeating: repeatOptions,
});

appendLog(logLevels.DEBUG,`Created event: ${eventSummary} - start: ${eventStart}; end: ${eventEnd}; enddate: ${endDate}; clsType: ${classType}`)
appendLog(logLevels.DEBUG,`Created event: ${eventSummary} - start: ${eventStart}; end: ${eventEnd}; untiltime: ${utilTime}; clsType: ${classType}`)
}

export function createCalendar(
Expand Down

0 comments on commit 7711a6a

Please sign in to comment.