diff --git a/src/timestamp.ml b/src/timestamp.ml index a63d74d1..7dfc68ec 100644 --- a/src/timestamp.ml +++ b/src/timestamp.ml @@ -1,3 +1,4 @@ +module T = struct type t = Ptime.t type span = Ptime.span @@ -20,8 +21,8 @@ let of_int_s s = Ptime.of_span @@ span_of_int_s s let of_int64_us us = Ptime.of_span @@ span_of_int64_us us let to_int_s t = Ptime.Span.to_int_s (Ptime.to_span t) -let to_int64_us span = - match to_int_s span with +let to_int64_us t = + match to_int_s t with | None -> None | Some s -> let us = Int64.(mul (of_int s) 1_000_000_L) in @@ -31,6 +32,24 @@ let now () = Ptime_clock.now () let add_span t span = Ptime.add_span t span let sub_span t span = Ptime.sub_span t span let diff a b = Ptime.diff a b +end + +type t = | T_uint64_us of int64 | Never + +let to_uint64 = + function | T_uint64_us us -> us | Never -> (* never/forever case := uint64_max *) + -1L + +let of_uint64 us = + if us = -1L then Never else T_uint64_us us + +let now () = + let opt = T.to_int64_us @@ + Ptime_clock.now () in + match opt with + | None -> Fmt.failure "invalid Ptime_clock.now value" + | Some us -> + (* (* microseconds since the UNIX Epoch, or "never" if None *) let jsont =