aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2021-10-04 12:46:08 +0200
committerAlban Gruin2021-10-04 12:46:08 +0200
commit3bed39113f475ae9b1243ab6a018169ef9bf8c92 (patch)
treeb94824807833d66f6ec37ea2665268a8e97560d6
parentcee4a3ef6aba480b54ae32b427ce4579832e5d69 (diff)
course, ics: location may be empty, make it an option
As there may not be a location, make it an option type so we can easily add a warning in the title of an event. Signed-off-by: Alban Gruin <alban at pa1ch dot fr>
-rw-r--r--src/course.ml4
-rw-r--r--src/ics.ml14
-rw-r--r--src/ics.mli3
3 files changed, 14 insertions, 7 deletions
diff --git a/src/course.ml b/src/course.ml
index 5ce2564..566ee0d 100644
--- a/src/course.ml
+++ b/src/course.ml
@@ -57,8 +57,8 @@ let loc_and_sum_to_groups = function
| Groups groups | Summary (groups, _) | Location (groups, _, _) -> groups
let loc_and_sum_to_location = function
- | Nothing | Groups _ | Summary _ -> ""
- | Location (_, _, location) -> location
+ | Nothing | Groups _ | Summary _ -> None
+ | Location (_, _, location) -> Some location
let loc_and_sum_to_summary category = function
| Nothing | Groups _ -> category
diff --git a/src/ics.ml b/src/ics.ml
index 4de1897..0f8c7d6 100644
--- a/src/ics.ml
+++ b/src/ics.ml
@@ -42,7 +42,7 @@ module Event = struct
start: Calendar.t;
stop: Calendar.t;
summary: string;
- location: string;
+ location: string option;
groups: string list;
}
@@ -50,14 +50,20 @@ module Event = struct
{start; stop; summary; location; groups}
let to_string date event id =
+ let summary, location = match event.location with
+ | None -> "[PAS DE SALLE] " ^ event.summary, ""
+ | Some location -> event.summary, location in
+ let attendees =
+ List.map (fun group -> "ATTENDEE:" ^ group) event.groups
+ |> String.concat "\r\n" in
["BEGIN:VEVENT";
"UID:" ^ date ^ "." ^ (string_of_int id) ^ "@ucs.pa1ch.fr";
"DTSTART:" ^ to_date event.start;
"DTEND:" ^ to_date event.stop;
"DTSTAMP:" ^ date;
- "SUMMARY:" ^ event.summary;
- "COMMENT:" ^ String.concat ", " event.groups;
- "LOCATION:" ^ event.location;
+ "SUMMARY:" ^ summary;
+ attendees;
+ "LOCATION:" ^ location;
"END:VEVENT\r\n"]
|> List.map ics_split_line
|> String.concat "\r\n"
diff --git a/src/ics.mli b/src/ics.mli
index f56a1a4..c2db3a2 100644
--- a/src/ics.mli
+++ b/src/ics.mli
@@ -19,7 +19,8 @@ module Event : sig
type t
val make : CalendarLib.Calendar.t -> CalendarLib.Calendar.t ->
- string -> string -> string list -> t
+ string -> string option -> string list -> t
+
val to_string : string -> t -> int -> string
end