wip int64 timestamp
This commit is contained in:
parent
32fa5b1fc3
commit
12a384a33a
8 changed files with 49 additions and 28 deletions
|
|
@ -1,6 +1,8 @@
|
|||
type t = Ptime.t option
|
||||
type span = Ptime.Span.t option
|
||||
|
||||
let now () = Ptime_clock.now () |> Option.some
|
||||
|
||||
let diff a b =
|
||||
match (a, b) with
|
||||
| None, _ | _, None -> None
|
||||
|
|
@ -56,9 +58,31 @@ let ptime_of_int64 i =
|
|||
| None -> Fmt.failwith "ptime_of_int64 error: `%Ld` is not a valid ptime" i
|
||||
| Some ts -> ts
|
||||
|
||||
let ptime_span_to_int64 span = span |> Ptime.Span.to_float_s |> Int64.of_float
|
||||
|
||||
let ptime_span_of_int64 i =
|
||||
match Ptime.Span.of_float_s (Int64.to_float i) with
|
||||
| None ->
|
||||
Fmt.failwith "span_of_int64 error: `%Ld` is not a valid ptime span" i
|
||||
| Some ts -> ts
|
||||
|
||||
(* - *)
|
||||
|
||||
let encode_int64 = function None -> Int64.max_int | Some p -> ptime_to_int64 p
|
||||
let decode_int64 i = if i = Int64.max_int then None else Some (ptime_of_int64 i)
|
||||
|
||||
let encode_span_int64 = function
|
||||
| None -> Int64.max_int
|
||||
| Some p -> ptime_span_to_int64 p
|
||||
|
||||
let decode_span_int64 i =
|
||||
if i = Int64.max_int then None else Some (ptime_span_of_int64 i)
|
||||
|
||||
let to_int64 = encode_int64
|
||||
let of_int64 = decode_int64
|
||||
let span_to_int64 = encode_span_int64
|
||||
let span_of_int64 = decode_span_int64
|
||||
|
||||
(* UINT64_MAX represents "never". *)
|
||||
let bin = Bin.map Bin.neint64 decode_int64 encode_int64
|
||||
let bin_nbo = Bin.map Bin.beint64 decode_int64 encode_int64
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue