Kalender-Abos Baustellen und Aufgaben für Outlook classic, Caddy lässt /kalender ohne Anmeldung durch
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
This commit is contained in:
72
src/domain/ical.ts
Normal file
72
src/domain/ical.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
// Internetkalender (iCalendar, RFC 5545) für das Kalender-Abo in Outlook classic (T11, E15).
|
||||
// Ganztägige Termine; Outlook holt Änderungen beim nächsten Abgleich ab, nur in eine Richtung.
|
||||
|
||||
import { type Datum, plusTage } from "./datum.js";
|
||||
|
||||
export interface Termin {
|
||||
uid: string;
|
||||
von: Datum;
|
||||
/** letzter Tag, eingeschlossen */
|
||||
bis: Datum;
|
||||
titel: string;
|
||||
beschreibung?: string;
|
||||
ort?: string;
|
||||
geaendert?: Date;
|
||||
}
|
||||
|
||||
function text(s: string): string {
|
||||
return s.replace(/\\/g, "\\\\").replace(/;/g, "\\;").replace(/,/g, "\\,").replace(/\r?\n/g, "\\n");
|
||||
}
|
||||
|
||||
/** Zeilen über 75 Byte umbrechen; Folgezeilen beginnen mit einem Leerzeichen. UTF-8-Zeichen bleiben ganz. */
|
||||
function falte(zeile: string): string {
|
||||
const teile: string[] = [];
|
||||
let aktuell = "";
|
||||
let bytes = 0;
|
||||
for (const z of zeile) {
|
||||
const n = new TextEncoder().encode(z).length;
|
||||
if (bytes + n > (teile.length ? 74 : 75)) {
|
||||
teile.push(aktuell);
|
||||
aktuell = "";
|
||||
bytes = 0;
|
||||
}
|
||||
aktuell += z;
|
||||
bytes += n;
|
||||
}
|
||||
teile.push(aktuell);
|
||||
return teile.join("\r\n ");
|
||||
}
|
||||
|
||||
const tag = (d: Datum) => d.replaceAll("-", "");
|
||||
const zeit = (d: Date) => d.toISOString().replace(/[-:]/g, "").replace(/\.\d{3}/, "");
|
||||
|
||||
export function kalender(name: string, termine: Termin[], jetzt = new Date()): string {
|
||||
const z = [
|
||||
"BEGIN:VCALENDAR",
|
||||
"VERSION:2.0",
|
||||
"PRODID:-//Schaarschmidt Holzbau//Betrieb//DE",
|
||||
"CALSCALE:GREGORIAN",
|
||||
"METHOD:PUBLISH",
|
||||
`X-WR-CALNAME:${text(name)}`,
|
||||
"X-WR-TIMEZONE:Europe/Berlin",
|
||||
"REFRESH-INTERVAL;VALUE=DURATION:PT1H",
|
||||
"X-PUBLISHED-TTL:PT1H",
|
||||
];
|
||||
for (const t of termine) {
|
||||
z.push(
|
||||
"BEGIN:VEVENT",
|
||||
`UID:${t.uid}`,
|
||||
`DTSTAMP:${zeit(jetzt)}`,
|
||||
...(t.geaendert ? [`LAST-MODIFIED:${zeit(t.geaendert)}`] : []),
|
||||
`DTSTART;VALUE=DATE:${tag(t.von)}`,
|
||||
`DTEND;VALUE=DATE:${tag(plusTage(t.bis, 1))}`,
|
||||
`SUMMARY:${text(t.titel)}`,
|
||||
...(t.beschreibung ? [`DESCRIPTION:${text(t.beschreibung)}`] : []),
|
||||
...(t.ort ? [`LOCATION:${text(t.ort)}`] : []),
|
||||
"TRANSP:TRANSPARENT",
|
||||
"END:VEVENT",
|
||||
);
|
||||
}
|
||||
z.push("END:VCALENDAR");
|
||||
return z.map(falte).join("\r\n") + "\r\n";
|
||||
}
|
||||
Reference in New Issue
Block a user