(* * Copyright (C) 2020 Alban Gruin * * ucs is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ucs is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with ucs. If not, see . *) open CalendarLib let to_date = Printer.Calendar.sprint "%Y%m%dT%H%M%SZ" let current_date () = to_date @@ Calendar.now () module Event = struct type t = { start: Calendar.t; stop: Calendar.t; summary: string; location: string; } let make start stop summary location = {start; stop; summary; location} let to_string date event id = Printf.sprintf "BEGIN:VEVENT\n\ UID:%s.%d@ucs.pa1ch.fr\n\ DTSTART:%s\n\ DTEND:%s\n\ DTSTAMP:%s\n\ SUMMARY:%s\n\ LOCATION:%s\n\ END:VEVENT\n" date id (to_date event.start) (to_date event.stop) date event.summary event.location end type t = Event.t list let make (events: t) = events let to_string events = let date = current_date () in let rec gen_events id str = function | [] -> str | event :: l -> gen_events (id + 1) (str ^ Event.to_string date event id) l in "BEGIN:VCALENDAR\n\ VERSION:2.0\n\ PRODID:-//ucs//\n" ^ gen_events 0 "" events ^ "END:VCALENDAR\n"