Skip to content

Commit 95699d3

Browse files
committed
fixup!
1 parent eab0ca3 commit 95699d3

3 files changed

Lines changed: 49 additions & 9 deletions

File tree

package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"devDependencies": {
2222
"@eslint/js": "^9.33.0",
23+
"@types/ical": "^0.8.3",
2324
"@types/properties-parser": "^0.3.3",
2425
"eslint": "^9.33.0",
2526
"eslint-plugin-import-x": "^4.16.1",

src/calendar.mjs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import ical from 'ical';
2+
3+
/**
4+
* Creates an ICAL instance from the input URL
5+
* @param {string} url
6+
*/
7+
const getEventsFromCalendar = async url => {
8+
const response = await fetch(url);
9+
const text = await response.text();
10+
11+
return Object.values(ical.parseICS(text));
12+
};
13+
214
/**
315
* Finds the next meeting event in Google Calendar for the current week
416
* @param {import('./types').MeetingConfig} meetingConfig - Meeting configuration object
517
* @returns {Promise<Date>} Calendar event object
618
*/
7-
export const findNextMeetingDate = async ({
8-
properties: { ICAL_URL, CALENDAR_FILTER, GROUP_NAME },
9-
}) => {
19+
export const findNextMeetingDate = async ({ properties }) => {
1020
const now = new Date();
1121

1222
// Calculate the start of the current week (Saturday 00:00:00 UTC)
@@ -23,21 +33,26 @@ export const findNextMeetingDate = async ({
2333
weekEnd.setUTCDate(weekStart.getUTCDate() + 6);
2434
weekEnd.setUTCHours(23, 59, 59, 999);
2535

26-
const ics = await fetch(ICAL_URL).then(r => r.text());
36+
const allEvents = await getEventsFromCalendar(properties.ICAL_URL);
2737

28-
const events = Object.values(ical.parseICS(ics)).filter(event =>
29-
(event.summary || event.description)?.includes(CALENDAR_FILTER)
38+
const filteredEvents = allEvents.filter(event =>
39+
// The event must be recurring
40+
event.rrule &&
41+
// The event must match our filter
42+
(event.summary || event.description)?.includes(properties.CALENDAR_FILTER)
3043
);
3144

32-
for (const event of events) {
33-
const duringOurTimeframe = event.rrule?.between(weekStart, weekEnd);
45+
for (const event of filteredEvents) {
46+
// Get all rucurrences in our timeframe
47+
const duringOurTimeframe = event.rrule.between(weekStart, weekEnd);
48+
3449
if (duringOurTimeframe.length > 0) {
3550
return duringOurTimeframe[0];
3651
}
3752
}
3853

3954
throw new Error(
40-
`No meeting found for ${GROUP_NAME || 'this group'} ` +
55+
`No meeting found for ${properties.GROUP_NAME || 'this group'} ` +
4156
`in the current week (${weekStart.toISOString().split('T')[0]} to ${weekEnd.toISOString().split('T')[0]}). ` +
4257
`This is expected for bi-weekly meetings or meetings that don't occur every week.`
4358
);

0 commit comments

Comments
 (0)