63 lines
2.1 KiB
OCaml
63 lines
2.1 KiB
OCaml
open Remind_sync
|
|
open Utils
|
|
|
|
type rem = {
|
|
original_uuid : string; (** Original UID from the iCalendar event *)
|
|
summary : string; (** Summary or title of the reminder *)
|
|
date : Timedesc.Date.t; (** Date specification (day, month, year) *)
|
|
end_date : Timedesc.Date.t option; (** Optional end date for a date range *)
|
|
time : Timedesc.Time.t option; (** Optional time specification (hour, minute) *)
|
|
duration : Timedesc.Span.t option; (** Optional duration for timed events *)
|
|
simple_yearly : (int * int) option; (** Optional simple yearly recurrence (month, day) *)
|
|
recurring : Icalendar.event list;
|
|
(** List of events that are part of the same recurring series: these are only the overrides, not the master event
|
|
*)
|
|
}
|
|
[@@deriving show]
|
|
(** A complete REM command *)
|
|
|
|
let empty =
|
|
{
|
|
original_uuid = "";
|
|
summary = "";
|
|
date = Timedesc.Date.Ymd.make_exn ~year:1970 ~month:1 ~day:1;
|
|
end_date = None;
|
|
time = None;
|
|
duration = None;
|
|
simple_yearly = None;
|
|
recurring = [];
|
|
}
|
|
|
|
let render_simple_yearly month day summary =
|
|
let month_str = month_of_int month |> string_of_month in
|
|
spf "REM %s %d MSG %s" month_str day summary
|
|
|
|
let string_of_rem rem =
|
|
match rem.simple_yearly with
|
|
| Some (month, day) -> render_simple_yearly month day rem.summary
|
|
| None -> begin
|
|
let b = Buffer.create 256 in
|
|
Buffer.add_string b "REM ";
|
|
Buffer.add_string b (spf "INFO \"UID: %s\" " rem.original_uuid);
|
|
Buffer.add_string b (Timedesc.Date.to_rfc3339 rem.date);
|
|
(match rem.time with
|
|
| Some time ->
|
|
Buffer.add_string b " AT ";
|
|
Buffer.add_string b (string_of_time time)
|
|
| None -> ());
|
|
(match rem.duration with
|
|
| Some duration ->
|
|
Buffer.add_string b " DURATION ";
|
|
Buffer.add_string b (string_of_span duration);
|
|
Buffer.add_string b ""
|
|
| None -> ());
|
|
(match rem.end_date with
|
|
| Some end_date ->
|
|
Buffer.add_string b " THROUGH ";
|
|
Buffer.add_string b (Timedesc.Date.to_rfc3339 end_date)
|
|
| None -> ());
|
|
Buffer.add_string b " MSG ";
|
|
Buffer.add_string b rem.summary;
|
|
Buffer.contents b
|
|
end
|