aboutsummaryrefslogtreecommitdiff
path: root/src/ics.ml
diff options
context:
space:
mode:
authorAlban Gruin2021-09-20 10:08:54 +0200
committerAlban Gruin2021-09-20 10:08:54 +0200
commit00cd66b16956a75a1c8dfb1f267b9a26603c09c7 (patch)
tree52dfe555af7de269518fcaed07420200bd04f7d2 /src/ics.ml
parent9522c817654c435f1929f4a37961780346406cf7 (diff)
ics, ucs: generate event IDs with a random number
Until now, ucs generated unique IDs with the datetime and the number of an event, starting by 0. Unfortunately, if two calendars were generated at the same second, they could have collisions. To avoid that, the ICS generator now uses a base ID generated randomly, which should be enough to avoid collisions. The RNG is self-initialised in the main function. Signed-off-by: Alban Gruin <alban at pa1ch dot fr>
Diffstat (limited to 'src/ics.ml')
-rw-r--r--src/ics.ml4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/ics.ml b/src/ics.ml
index 732cbd5..4de1897 100644
--- a/src/ics.ml
+++ b/src/ics.ml
@@ -19,6 +19,8 @@ open CalendarLib
module StringSet = Set.Make (String)
+let rng_bound = int_of_float (2. ** 30.) - 1
+
let to_date = Printer.Calendar.sprint "%Y%m%dT%H%M%S"
let current_date () = to_date @@ Calendar.now ()
@@ -101,5 +103,5 @@ let to_string tz events =
VERSION:2.0\r\n\
PRODID:-//ucs//\r\n"
^ vtimezone
- ^ gen_events 0 "" events
+ ^ gen_events (Random.int rng_bound) "" events
^ "END:VCALENDAR\r\n"