From f2635cce682e784964a72fcd2e830ac197db18e6 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 17 Dec 2025 11:13:34 -0500 Subject: [PATCH] move timestamp to util --- src/core/timestamp_ns.ml | 30 +----------------------------- src/util/timestamp_ns.ml | 8 ++++++++ 2 files changed, 9 insertions(+), 29 deletions(-) create mode 100644 src/util/timestamp_ns.ml diff --git a/src/core/timestamp_ns.ml b/src/core/timestamp_ns.ml index 52f7cfa2..75ca5669 100644 --- a/src/core/timestamp_ns.ml +++ b/src/core/timestamp_ns.ml @@ -1,29 +1 @@ -(** Unix timestamp. - - These timestamps measure time since the Unix epoch (jan 1, 1970) UTC in - nanoseconds. *) - -type t = int64 - -open struct - let ns_in_a_day = Int64.(mul 1_000_000_000L (of_int (24 * 3600))) -end - -(** Current unix timestamp in nanoseconds *) -let[@inline] now_unix_ns () : t = - let span = Ptime_clock.now () |> Ptime.to_span in - let d, ps = Ptime.Span.to_d_ps span in - let d = Int64.(mul (of_int d) ns_in_a_day) in - let ns = Int64.(div ps 1_000L) in - Int64.(add d ns) - -let pp_debug out (self : t) = - let d = Int64.(to_int (div self ns_in_a_day)) in - let ns = Int64.(rem self ns_in_a_day) in - let ps = Int64.(mul ns 1_000L) in - match Ptime.Span.of_d_ps (d, ps) with - | None -> Format.fprintf out "ts: <%Ld ns>" self - | Some span -> - (match Ptime.add_span Ptime.epoch span with - | None -> Format.fprintf out "ts: <%Ld ns>" self - | Some ptime -> Ptime.pp_human () out ptime) +include Opentelemetry_util.Timestamp_ns diff --git a/src/util/timestamp_ns.ml b/src/util/timestamp_ns.ml new file mode 100644 index 00000000..73e4f3ef --- /dev/null +++ b/src/util/timestamp_ns.ml @@ -0,0 +1,8 @@ +(** Unix timestamp. + + These timestamps measure time since the Unix epoch (jan 1, 1970) UTC in + nanoseconds. *) + +type t = int64 + +let pp_debug out (self : t) = Format.fprintf out "" self