import * as ics from "ics" import { prepare } from "./main.js" import { c, writeICS } from "./files.js" const daymap = { "Mo": "MO", "Di": "TU", "Mi": "WE", "Do": "TH", "Fr": "FR", } let start = new Date(c.vorlesungszeit[0]) let end = new Date(c.vorlesungszeit[1]) function getDateList(date, time) { let year = date.getFullYear() - 0 let month = date.getMonth() - 0 let day = date.getDate() - 0 let timelist = time.split(":") let hour = timelist[0] - 0 let minute = timelist[1] - 0 return [year, month, day, hour, minute] } function generateICS() { let tage = prepare(true); let veranstaltungen = [] for (let tag in tage) { for (let eintrag of tage[tag]) { let until = end.toISOString().replace(/-|\.|:/g, "").replace("000000000", "000000"); let day = daymap[tag]; if (!eintrag.name.includes("STYLECLASS")) { veranstaltungen.push({ title: eintrag.name, location: eintrag.raum, start: getDateList(start, eintrag.von), end: getDateList(start, eintrag.bis), // yes this is correct recurrenceRule: `FREQ=WEEKLY;INTERVAL=1;BYDAY=${day};UNTIL=${until}` }) } } start.setDate(start.getDate() + 1); } const { error, value } = ics.createEvents(veranstaltungen) if (error) { console.log(error) } else { writeICS(value) } } generateICS()