diff options
author | Alban Gruin | 2020-09-12 00:08:44 +0200 |
---|---|---|
committer | Alban Gruin | 2020-09-12 01:39:15 +0200 |
commit | bfcd4b6c5b3f4d0baaec8ef99e79c4c4adcd7d10 (patch) | |
tree | b9e743a5732711f7404296ee07e5916397baf550 | |
parent | d11f5875b52e86fd28b3f1de805d5af4d108d8e5 (diff) |
course: avoid crashes for events spanning on a whole day
Signed-off-by: Alban Gruin <alban at pa1ch dot fr>
-rw-r--r-- | src/course.ml | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/course.ml b/src/course.ml index 0c93075..9f16646 100644 --- a/src/course.ml +++ b/src/course.ml @@ -20,7 +20,6 @@ open CalendarLib module J = Json_encoding let date_format = "%FT%T" -let default_date = Calendar.make 1970 1 1 0 0 0 let separator = Str.regexp_string "\r\n\r\n<br />\r\n\r\n" let group_prefixes = ["MAT-Agreg Interne "; "3EME ANNEE "; "2EME ANNEE "; @@ -63,16 +62,19 @@ let date = let encoding = J.(conv - (fun _ -> (default_date, default_date, "", "", (), (), ()), + (fun _ -> (None, None, "", "", (), (), ()), ((), (), (), (), (), (), (), (), (), ())) (fun ((start, stop, description, category, (), (), ()), ((), (), (), (), (), (), (), (), (), ())) -> let location, summary = location_and_summary description category in - Ics.Event.make start stop summary location) + match start, stop with + | Some start, Some stop -> + Some (Ics.Event.make start stop summary location) + | _, _ -> None) (merge_objs (obj7 - (req "start" date) - (req "end" date) + (req "start" @@ option date) + (req "end" @@ option date) (req "description" string) (req "eventCategory" string) (req "id" unit) @@ -95,4 +97,6 @@ let decode s = match s with | "" -> `O [] | s -> Ezjsonm.from_string s in - Ics.make @@ J.destruct (J.list encoding) toks + J.(destruct (list encoding) toks) + |> List.filter_map (fun (event: Ics.Event.t option) -> event) + |> Ics.make |