2025-10-17 15:09:47 +02:00
|
|
|
(* -- Ptime -- *)
|
|
|
|
|
|
2025-11-21 19:29:04 +01:00
|
|
|
(* TODO have a Time.t = int64
|
|
|
|
|
-> avoid having conversion everywhere
|
|
|
|
|
-> avoid using Caqti_type.ptime *)
|
2025-11-16 05:33:06 +01:00
|
|
|
let ptime_to_int64 ptime = ptime |> Ptime.to_float_s |> Int64.of_float
|
|
|
|
|
|
|
|
|
|
let ptime_of_int64 i =
|
|
|
|
|
match Ptime.of_float_s (Int64.to_float i) with
|
|
|
|
|
| None -> Fmt.error "ptime_of_int64 error: `%Ld` is not a valid ptime" i
|
|
|
|
|
| Some ts -> Ok ts
|
2025-10-17 15:09:47 +02:00
|
|
|
|
|
|
|
|
let ptime_of_span_exn span =
|
|
|
|
|
match Ptime.of_span span with
|
|
|
|
|
| None -> Fmt.failwith "Ptime.of_span: not in the range [min;max]"
|
|
|
|
|
| Some p -> p
|
|
|
|
|
|
|
|
|
|
let ptime_add_span_exn p span =
|
|
|
|
|
match Ptime.add_span p span with
|
|
|
|
|
| None -> Fmt.failwith "Ptime.add_span: not in the range [min;max]"
|
|
|
|
|
| Some v -> v
|
2025-10-17 15:25:10 +02:00
|
|
|
|
|
|
|
|
(* -- *** -- *)
|
|
|
|
|
|
|
|
|
|
(* TODO bin
|
|
|
|
|
- no [Bin.of_string] ? *)
|
|
|
|
|
let bin_of_string bin s =
|
|
|
|
|
let v = Bin.decode bin s (ref 0) in
|
|
|
|
|
Ok v
|