diff --git a/README.md b/README.md index 3f19a70..593b299 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,9 @@ AH_PASSWORD=password TZ=Europe/Amsterdam STORE_PATH=/db + +CALENDAR_NOTIFY_MINUTES=15,120 # In minutes, use a "," to use multiple reminders + ``` ### Calendar Synchronization diff --git a/src/utils/server/createIcs.ts b/src/utils/server/createIcs.ts index e6d2d89..bad9daf 100644 --- a/src/utils/server/createIcs.ts +++ b/src/utils/server/createIcs.ts @@ -10,6 +10,7 @@ export interface IcsEvent { end: DateTime; description: string; summary: string; + alarms: number[]; } const formatTime = (date: DateTime): string => @@ -32,6 +33,16 @@ export const createIcs = ( ]; events.forEach((event) => { + const alarms = event.alarms.map((alarm) => + [ + "BEGIN:VALARM", + `TRIGGER:-PT${alarm}M`, + "ACTION:DISPLAY", + `DESCRIPTION:${event.summary}`, + "END:VALARM" + ].join("\r\n") + ); + ics.push( ...[ "BEGIN:VEVENT", @@ -42,6 +53,7 @@ export const createIcs = ( `DESCRIPTION:${event.description}`, "STATUS:CONFIRMED", `UID:${event.end.toMillis() + "-" + event.start.toMillis()}`, + ...alarms, "END:VEVENT" ] ); diff --git a/src/utils/server/env.ts b/src/utils/server/env.ts index d1b5c80..3c5124f 100644 --- a/src/utils/server/env.ts +++ b/src/utils/server/env.ts @@ -12,3 +12,10 @@ export const storePath = env.STORE_PATH export const timesheetCacheDuration = env.TIMESHEET_CACHE ? +env.TIMESHEET_CACHE : 3600; + +export const calendarNotifyMinutes = ( + process.env.CALENDAR_NOTIFY_MINUTES ?? "60" +) + .split(",") + .map((i) => parseInt(i)) + .filter(Boolean); diff --git a/src/utils/server/timesheetToIcs.ts b/src/utils/server/timesheetToIcs.ts index 837ec07..125ad73 100644 --- a/src/utils/server/timesheetToIcs.ts +++ b/src/utils/server/timesheetToIcs.ts @@ -1,3 +1,5 @@ +import { calendarNotifyMinutes } from "./env"; + import { DateTime } from "luxon"; import { createIcs, IcsEvent } from "@server"; @@ -12,7 +14,8 @@ export const timesheetToIcs = (timesheet: LuxonTimesheet): string => { description: `Geüpdated op ${timesheet.updated .setLocale("nl") - .toLocaleString(DateTime.DATETIME_MED)}` + .toLocaleString(DateTime.DATETIME_MED)}`, + alarms: calendarNotifyMinutes })); return createIcs({ name: "Shifts", updated: timesheet.updated }, events);