aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ics.ml33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/ics.ml b/src/ics.ml
index 2ee0269..bf895b0 100644
--- a/src/ics.ml
+++ b/src/ics.ml
@@ -20,6 +20,19 @@ open CalendarLib
let to_date = Printer.Calendar.sprint "%Y%m%dT%H%M%SZ"
let current_date () = to_date @@ Calendar.now ()
+let ics_split_line =
+ let max_line_length = 73 in
+ let rec aux accu str =
+ String.(
+ let l = length str in
+ if l > max_line_length then
+ let b = sub str 0 max_line_length and
+ e = sub str max_line_length (l - max_line_length) in
+ aux (accu ^ b ^ "\r\n ") e
+ else
+ accu ^ str) in
+ aux ""
+
module Event = struct
type t = {
start: Calendar.t;
@@ -32,16 +45,16 @@ module Event = struct
{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
+ ["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;
+ "LOCATION:" ^ event.location;
+ "END:VEVENT\n"]
+ |> List.map ics_split_line
+ |> String.concat "\n"
end
type t = Event.t list