-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcal_api_util.ml
53 lines (48 loc) · 1.72 KB
/
gcal_api_util.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(* Google calendar events manipulation *)
open Gcal_api_t
(* Compare events by their start time. Events with start time
corresponding to a None option are considered as all day events
and are less than events with a start time. *)
let compare_events_by_start_time get_event e1 e2 =
match (get_event e1).ev_start, (get_event e2).ev_start with
Some {dateTime=Some time1}, Some {dateTime=Some time2} ->
Util_time.compare time1 time2
| Some {dateTime=None}, Some {dateTime=None} ->
0
| Some {dateTime=None}, Some {dateTime=Some time2} ->
-1
| Some {dateTime=Some time1}, Some {dateTime=None} ->
1
| _ -> assert false
(* Filters out cancelled events and sorts the result. get_event is
a function that fetches an event from an element of l. All day events
are considered less than events with a start time. *)
let sort_events_by_start_time l get_event =
let scheduled_events =
List.filter (fun x -> (get_event x).ev_start <> None) l
in
List.stable_sort (compare_events_by_start_time get_event) scheduled_events
(*
Simplify a calendar obtained from CalendarsList into
a calendar obtained from Calendars.
Not sure why they are different things:
https://developers.google.com/google-apps/calendar/concepts#calendar_vs_calendarList
*)
let calendar_metadata_of_calendar_list_item
(x : calendar_list_item) : calendar_metadata =
{
gcal_kind = x.ci_kind;
gcal_etag = x.ci_etag;
gcal_id = x.ci_id;
gcal_summary = x.ci_summary;
gcal_description = x.ci_description;
gcal_location = x.ci_location;
gcal_timeZone = x.ci_timeZone;
}
let get_timezone x =
match x.ci_timeZone with
| None ->
(* don't know if this ever happens *)
"UTC"
| Some tz ->
tz