Skip to content

Commit

Permalink
ICS endpoint: Add alarm/reminder setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Netfloex committed Mar 26, 2023
1 parent 2b82f53 commit 794566f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/utils/server/createIcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface IcsEvent {
end: DateTime;
description: string;
summary: string;
alarms: number[];
}

const formatTime = (date: DateTime): string =>
Expand All @@ -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",
Expand All @@ -42,6 +53,7 @@ export const createIcs = (
`DESCRIPTION:${event.description}`,
"STATUS:CONFIRMED",
`UID:${event.end.toMillis() + "-" + event.start.toMillis()}`,
...alarms,
"END:VEVENT"
]
);
Expand Down
7 changes: 7 additions & 0 deletions src/utils/server/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
5 changes: 4 additions & 1 deletion src/utils/server/timesheetToIcs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { calendarNotifyMinutes } from "./env";

import { DateTime } from "luxon";

import { createIcs, IcsEvent } from "@server";
Expand All @@ -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);
Expand Down

0 comments on commit 794566f

Please sign in to comment.