Compare commits

..

2 Commits

Author SHA1 Message Date
49aad0c27f fix: use deterministic hash for SCHED/WARN function names
Replaces the global sequential counter (sched_1, warn_2, …) with a
polynomial hash of (UUID ^ date), so names are stable across runs and
unique across calendars — eliminating "function redefined" errors when
multiple .rem files are included by Remind.
2026-06-19 23:34:05 +02:00
244e001d2a fix: use %b %3 instead of %1 in timed alarm MSG
%b %3 shows both day offset and verbose time remaining, giving more
context when the reminder fires the day before the event.
2026-06-19 23:16:58 +02:00

View File

@@ -80,12 +80,13 @@ let empty =
(* ── alarm rendering ─────────────────────────────────────────── *) (* ── alarm rendering ─────────────────────────────────────────── *)
(** Global counter for generating unique WARN/SCHED function names *) (** Deterministic alarm function name tag derived from the event UID and date. Using both fields ensures uniqueness
let alarm_id = ref 0 across calendars (UUID is globally unique) and between a master event and its date-specific overrides (which share
the same UUID). *)
let next_alarm_id () = let alarm_hash rem =
incr alarm_id; let key = rem.original_uuid ^ Timedesc.Date.to_rfc3339 rem.date in
!alarm_id let h = String.fold_left (fun acc c -> ((acc * 1000003) + Char.code c) land 0x3FFFFFFF) 0 key in
spf "%08x" h
(** Convert a Timedesc.Span.t to signed total minutes. Negative = before event; positive = after event. *) (** Convert a Timedesc.Span.t to signed total minutes. Negative = before event; positive = after event. *)
let span_to_minutes (sp : Timedesc.Span.t) : int = let span_to_minutes (sp : Timedesc.Span.t) : int =
@@ -141,8 +142,7 @@ let render_alarm (rem : rem) : alarm_rendering =
| [] -> empty_alarm | [] -> empty_alarm
| [ n ] -> { empty_alarm with time_delta = spf "+%d " n } | [ n ] -> { empty_alarm with time_delta = spf "+%d " n }
| mins -> | mins ->
let id = next_alarm_id () in let name = spf "sched_%s" (alarm_hash rem) in
let name = spf "sched_%d" id in
(* SCHED sequence: most-advance first (most negative), then 0 to stop. (* SCHED sequence: most-advance first (most negative), then 0 to stop.
mins is sorted ascending (closest first), so reverse for SCHED order. *) mins is sorted ascending (closest first), so reverse for SCHED order. *)
let sched_vals = List.rev_map (fun n -> spf "%d" (-n)) mins @ [ "0" ] in let sched_vals = List.rev_map (fun n -> spf "%d" (-n)) mins @ [ "0" ] in
@@ -155,8 +155,7 @@ let render_alarm (rem : rem) : alarm_rendering =
| [] -> empty_alarm | [] -> empty_alarm
| [ n ] -> { empty_alarm with day_delta = spf "++%d " n } | [ n ] -> { empty_alarm with day_delta = spf "++%d " n }
| days -> | days ->
let id = next_alarm_id () in let name = spf "warn_%s" (alarm_hash rem) in
let name = spf "warn_%d" id in
(* WARN sequence: furthest first (days sorted descending), then 0 to stop. *) (* WARN sequence: furthest first (days sorted descending), then 0 to stop. *)
let warn_vals = List.map string_of_int (days @ [ 0 ]) in let warn_vals = List.map string_of_int (days @ [ 0 ]) in
let fset = spf "FSET %s(x) choose(x, %s)\n" name (String.concat ", " warn_vals) in let fset = spf "FSET %s(x) choose(x, %s)\n" name (String.concat ", " warn_vals) in
@@ -274,7 +273,9 @@ let escape_msg s =
let add_msg b ?(alarm = empty_alarm) ?(timed = false) summary = let add_msg b ?(alarm = empty_alarm) ?(timed = false) summary =
let has_alarm = alarm.day_delta <> "" || alarm.time_delta <> "" || alarm.sched <> "" in let has_alarm = alarm.day_delta <> "" || alarm.time_delta <> "" || alarm.sched <> "" in
let body = escape_msg summary in let body = escape_msg summary in
let body = if has_alarm then if timed then spf "%%\"%s%%\" (%%1)" body else spf "%%\"%s%%\" (%%b)" body else body in let body =
if has_alarm then if timed then spf "%%\"%s%%\" (%%b %%3)" body else spf "%%\"%s%%\" (%%b)" body else body
in
Buffer.add_string b (spf " MSG %s\n" body) Buffer.add_string b (spf " MSG %s\n" body)
let add_location b loc = let add_location b loc =