fix: use event TZID for UNTIL date conversion

Add a `tz` field to `rem` to carry the event's DTSTART timezone, and
introduce `timedesc_of_utc_or_timestamp_tz` to convert UNTIL timestamps
in that timezone instead of the process locale. This makes UNTIL
comparisons locale-independent for events with a known TZID.
This commit is contained in:
2026-05-18 00:17:04 +02:00
parent e2b4d71cee
commit 7644489ecf
3 changed files with 24 additions and 4 deletions

View File

@@ -45,6 +45,7 @@ type rem = {
*)
exdate : Icalendar.date_or_datetime list; (** List of excluded dates for recurring events *)
overrides : rem list; (** Single-event REMs generated from non-cancelled RECURRENCE-ID overrides *)
tz : Timedesc.Time_zone.t option; (** Timezone of the event's DTSTART, used for UNTIL conversion *)
}
(** A complete REM command *)
@@ -64,6 +65,7 @@ let empty =
recurring = [];
exdate = [];
overrides = [];
tz = None;
}
(* ── buffer primitives ────────────────────────────────────────── *)
@@ -97,7 +99,8 @@ let add_until b rem (w : simple_weekly) =
match w.count_or_until with
| None -> ()
| Some (`Until d) ->
let ts = timedesc_of_utc_or_timestamp_local d in
let tz = Option.value ~default:(Timedesc.Time_zone.local_exn ()) rem.tz in
let ts = timedesc_of_utc_or_timestamp_tz tz d in
let date = until_date_adjusted ts rem.time in
Buffer.add_string b (spf "UNTIL %s " (Timedesc.Date.to_rfc3339 date))
| Some (`Count count) ->
@@ -116,7 +119,8 @@ let add_until_daily b rem (d : simple_daily) =
match d.count_or_until with
| None -> ()
| Some (`Until dt) ->
let ts = timedesc_of_utc_or_timestamp_local dt in
let tz = Option.value ~default:(Timedesc.Time_zone.local_exn ()) rem.tz in
let ts = timedesc_of_utc_or_timestamp_tz tz dt in
let date = until_date_adjusted ts rem.time in
Buffer.add_string b (spf "UNTIL %s " (Timedesc.Date.to_rfc3339 date))
| Some (`Count count) ->
@@ -128,7 +132,8 @@ let add_until_monthly b rem (m : simple_monthly) =
match m.count_or_until with
| None -> ()
| Some (`Until dt) ->
let ts = timedesc_of_utc_or_timestamp_local dt in
let tz = Option.value ~default:(Timedesc.Time_zone.local_exn ()) rem.tz in
let ts = timedesc_of_utc_or_timestamp_tz tz dt in
let date = until_date_adjusted ts rem.time in
Buffer.add_string b (spf "UNTIL %s " (Timedesc.Date.to_rfc3339 date))
| Some (`Count count) ->