diff --git a/bin/eventPredicates.ml b/bin/eventPredicates.ml index 3718a4d..3ea0624 100644 --- a/bin/eventPredicates.ml +++ b/bin/eventPredicates.ml @@ -173,7 +173,12 @@ open Utils *) type event_description = - [ `Collect_uuid | `Has_summary | `All_day_event | `Expand_recurrence | `Simple_weekly_recurrence ] + [ `Collect_uuid + | `Has_summary + | `All_day_event + | `Expand_recurrence + | `Yearly_simple_date + | `Simple_weekly_recurrence ] [@@deriving show] type error = Invalid_date of string | Skip [@@deriving show] @@ -249,8 +254,15 @@ let collect_start_end_duration rem ev : (Remind.rem, error) result = let expand_recurrence rem ev : (Remind.rem, error) result = if List.length rem.Remind.recurring > 0 then skip else Ok rem -let simple_weekly_recurrence rem ev : (Remind.rem, error) result = +let yearly_simple_date rem ev : (Remind.rem, error) result = match ev.rrule with + | Some (_, (`Yearly, None, None, [])) -> + let month, day = (Timedesc.Date.month rem.Remind.date, Timedesc.Date.day rem.Remind.date) in + Ok { rem with Remind.simple_yearly = Some (month, day) } + | Some _ -> Ok rem + | None -> Ok rem + +let simple_weekly_recurrence rem ev : (Remind.rem, error) result = (* type recur = [ `Byminute of int list @@ -272,27 +284,32 @@ type recurrence = freq * count_or_until option * interval option * recur list [@ QUESTE SONO **TUTTE** LE RRULE NEL MIO DATASET -RRULE: (`Daily, (Some `Count (11)), None, []) -RRULE: (`Daily, (Some `Until (`Utc (2008-05-11 11:15:00 +00:00))), None, [`Weekday (`Monday)]) -RRULE: (`Daily, (Some `Until (`Utc (2026-02-04 13:30:00 +00:00))), (Some 1), []) -RRULE: (`Weekly, (Some `Count (3)), None, [`Byday ([(0, `Wednesday)])]) -RRULE: (`Weekly, (Some `Until (`Utc (2009-07-31 18:00:00 +00:00))), None, [`Byday ([(0, `Tuesday); (0, `Friday)]); `Weekday (`Monday)]) -RRULE: (`Weekly, (Some `Until (`Utc (2013-04-18 17:30:00 +00:00))), None, [`Byday ([(0, `Monday); (0, `Thursday)])]) -RRULE: (`Weekly, (Some `Until (`Utc (2014-12-20 10:30:00 +00:00))), None, [`Byday ([(0, `Saturday)])]) -RRULE: (`Weekly, (Some `Until (`Utc (2020-09-16 21:59:59 +00:00))), None, [`Byday ([(0, `Thursday)])]) -RRULE: (`Weekly, (Some `Until (`Utc (2021-08-25 21:59:59 +00:00))), None, [`Byday ([(0, `Wednesday)]); `Weekday (`Monday)]) -RRULE: (`Weekly, (Some `Until (`Utc (2021-09-18 21:59:59 +00:00))), (Some 1), [`Byday ([(0, `Sunday)]); `Weekday (`Monday)]) -RRULE: (`Weekly, (Some `Until (`Utc (2024-06-12 08:00:00 +00:00))), (Some 4), [`Weekday (`Sunday); `Byday ([(0, `Wednesday)])]) -RRULE: (`Weekly, (Some `Until (`Utc (2025-02-04 22:59:59 +00:00))), (Some 1), [`Weekday (`Sunday); `Byday ([(0, `Wednesday)])]) -RRULE: (`Weekly, (Some `Until (`Utc (2025-06-22 21:59:59 +00:00))), (Some 1), [`Weekday (`Monday); `Byday ([(0, `Monday)])]) -RRULE: (`Weekly, (Some `Until (`Utc (2026-02-24 22:59:59 +00:00))), (Some 2), [`Weekday (`Monday); `Byday ([(0, `Tuesday)])]) -RRULE: (`Weekly, (Some `Until (`Utc (2026-03-25 00:00:00 +00:00))), None, [`Weekday (`Monday); `Byday ([(0, `Wednesday)])]) -RRULE: (`Weekly, (Some `Until (`Utc (2026-07-01 09:00:00 +00:00))), None, []) -RRULE: (`Yearly, None, None, []) - -Il file RRULE_all.txt contiene tutte le RRULE del mio dataset! - +RRULE: (`Daily, (Some `Count (11)), None, []) UID: 0b48208b22php2mv6r157rk23v@google.com +RRULE: (`Daily, (Some `Count (11)), None, []) UID: 0cb95edhq1d00bd3gcpomb9mcg@google.com +RRULE: (`Daily, (Some `Count (11)), None, []) UID: 0kbt3i5d6dpq6uncmhlcr335vq@google.com +RRULE: (`Daily, (Some `Until (`Utc (2008-05-11 11:15:00 +00:00))), None, [`Weekday (`Monday)]) UID: dmkfr0h3p1fq6p6v8i62vm1n4k@google.com +RRULE: (`Daily, (Some `Until (`Utc (2008-05-11 15:00:00 +00:00))), None, [`Weekday (`Monday)]) UID: bh5mhev3uq6p5casisrqufksd8@google.com +RRULE: (`Daily, (Some `Until (`Utc (2014-12-24 22:00:00 +00:00))), None, [`Weekday (`Monday)]) UID: tsdjd2jlcsgi0c0ei1celg41v4@google.com +RRULE: (`Daily, (Some `Until (`Utc (2014-12-25 10:00:00 +00:00))), None, [`Weekday (`Monday)]) UID: ha0rjkp62uqh3boc9n6k4f6cuo@google.com +RRULE: (`Daily, (Some `Until (`Utc (2025-05-22 07:00:00 +00:00))), (Some 1), []) UID: 040000008200E00074C5B7101A82E008000000008FD3AF9B24B9DB01000000000000000010000000A152B8147DB736439366702297C68F98 +RRULE: (`Daily, (Some `Until (`Utc (2026-02-04 13:30:00 +00:00))), (Some 1), []) UID: 040000008200E00074C5B7101A82E00800000000CEF108493A94DC010000000000000000100000005D7F32754B6575419990179984830EFC +RRULE: (`Weekly, (Some `Count (3)), None, [`Byday ([(0, `Wednesday)])]) UID: 605de987-4600-419f-a40a-eb585b7e1ba2 +RRULE: (`Weekly, (Some `Count (7)), (Some 2), [`Byday ([(0, `Tuesday)])]) UID: 13C-6A06C880-D-48221A00 +RRULE: (`Weekly, (Some `Until (`Utc (2009-07-31 18:00:00 +00:00))), None, [`Byday ([(0, `Tuesday); (0, `Friday)]); `Weekday (`Monday)]) UID: hrpg4ovdou2ae57pqb9niobb3c@google.com +RRULE: (`Weekly, (Some `Until (`Utc (2013-04-18 17:30:00 +00:00))), None, [`Byday ([(0, `Monday); (0, `Thursday)])]) UID: ool8g85jgfd5db57mdqbkt52nk@google.com +RRULE: (`Weekly, (Some `Until (`Utc (2014-12-20 10:30:00 +00:00))), None, [`Byday ([(0, `Saturday)])]) UID: rr96e7fr98g8j9vner8mmdtfls@google.com +RRULE: (`Weekly, (Some `Until (`Utc (2020-09-16 21:59:59 +00:00))), None, [`Byday ([(0, `Thursday)])]) UID: 5n174r33j7ep7t5eete9307949@google.com +RRULE: (`Weekly, (Some `Until (`Utc (2021-08-25 21:59:59 +00:00))), None, [`Byday ([(0, `Wednesday)]); `Weekday (`Monday)]) UID: 20kb6se0oog5e9hi5l7uu6jiq6@google.com +RRULE: (`Weekly, (Some `Until (`Utc (2021-09-18 21:59:59 +00:00))), (Some 1), [`Byday ([(0, `Sunday)]); `Weekday (`Monday)]) UID: 6sp30e9oc4sjebb264o3gb9kcos3ab9pccoj2b9j6kom2chjcco6ad9nck@google.com +RRULE: (`Weekly, (Some `Until (`Utc (2024-06-12 08:00:00 +00:00))), (Some 4), [`Weekday (`Sunday); `Byday ([(0, `Wednesday)])]) UID: 040000008200E00074C5B7101A82E00800000000DD1EB23CE8ACDA01000000000000000010000000FED71D085A97144F8C716EC999301E3A +RRULE: (`Weekly, (Some `Until (`Utc (2025-02-04 22:59:59 +00:00))), (Some 1), [`Weekday (`Sunday); `Byday ([(0, `Wednesday)])]) UID: _60q30c1g60o30e1i60o4ac1g60rj8gpl88rj2c1h84s34h9g60s30c1g60o30c1g85248hhg6kq30hhn6ork8ghg64o30c1g60o30c1g60o30c1g60o32c1g60o30c1g6kqj4g9g89234chl852kadpk890j2h9m6op44dpn6t238h1k8ks0_R20250129T080000@google.com +RRULE: (`Weekly, (Some `Until (`Utc (2025-06-22 21:59:59 +00:00))), (Some 1), [`Weekday (`Monday); `Byday ([(0, `Monday)])]) UID: 040000008200E00074C5B7101A82E00800000000AE5AF0ED6ADCDB0100000000000000001000000040E4ACABB0843749950BEB4B273F862E +RRULE: (`Weekly, (Some `Until (`Utc (2026-02-24 22:59:59 +00:00))), (Some 2), [`Weekday (`Monday); `Byday ([(0, `Tuesday)])]) UID: fjlqvi1ekuefpa8rb65meoklct@google.com +RRULE: (`Weekly, (Some `Until (`Utc (2026-03-25 00:00:00 +00:00))), None, [`Weekday (`Monday); `Byday ([(0, `Wednesday)])]) UID: 1iue0uq2l3imtfdsff785o9u35@google.com +RRULE: (`Weekly, (Some `Until (`Utc (2026-07-01 09:00:00 +00:00))), None, []) UID: 4479f7fd-7be9-470f-bc10-5ed61636547b *) + match ev.rrule with + | Some (_, (`Yearly, None, None, [])) -> Ok rem | Some (_, (freq, count_or_until, interval, recurs)) -> let _recur = (freq, count_or_until, interval, recurs) in let uid = Utils.get_uid ev in @@ -307,6 +324,7 @@ let all_collectors : (collector * event_description) list = (collect_summary, `Has_summary); (collect_start_end_duration, `All_day_event); (expand_recurrence, `Expand_recurrence); + (yearly_simple_date, `Yearly_simple_date); (simple_weekly_recurrence, `Simple_weekly_recurrence); ] diff --git a/bin/remind.ml b/bin/remind.ml index b35379d..e725b5e 100644 --- a/bin/remind.ml +++ b/bin/remind.ml @@ -8,6 +8,7 @@ type rem = { 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 *) @@ -23,30 +24,39 @@ let empty = 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 = - 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 + 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 diff --git a/bin/utils.ml b/bin/utils.ml index 9ab59d8..fe0322a 100644 --- a/bin/utils.ml +++ b/bin/utils.ml @@ -1,6 +1,37 @@ open Remind_sync open Icalendar +type months = Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec + +let month_of_int = function + | 1 -> Jan + | 2 -> Feb + | 3 -> Mar + | 4 -> Apr + | 5 -> May + | 6 -> Jun + | 7 -> Jul + | 8 -> Aug + | 9 -> Sep + | 10 -> Oct + | 11 -> Nov + | 12 -> Dec + | _ -> failwith "Invalid month number" + +let string_of_month = function + | Jan -> "Jan" + | Feb -> "Feb" + | Mar -> "Mar" + | Apr -> "Apr" + | May -> "May" + | Jun -> "Jun" + | Jul -> "Jul" + | Aug -> "Aug" + | Sep -> "Sep" + | Oct -> "Oct" + | Nov -> "Nov" + | Dec -> "Dec" + let spf = Printf.sprintf let get_uid ev =