Shell: add Time.{Map,Set,Table}
This commit is contained in:
parent
a891e23741
commit
ad035d7679
@ -10,11 +10,23 @@
|
||||
open Error_monad
|
||||
open CalendarLib
|
||||
|
||||
type t = int64
|
||||
module T = struct
|
||||
include Int64
|
||||
|
||||
let compare = Int64.compare
|
||||
let (=) x y = compare x y = 0
|
||||
let equal = (=)
|
||||
let diff a b =
|
||||
let sign = a >= b in
|
||||
let res = Int64.sub a b in
|
||||
let res_sign = res >= 0L in
|
||||
if sign = res_sign then res else invalid_arg "Time.diff" ;;
|
||||
|
||||
let add a d =
|
||||
let sign = d >= 0L in
|
||||
let res = Int64.add a d in
|
||||
let incr_sign = res >= a in
|
||||
if sign = incr_sign then res else invalid_arg "Time.add" ;;
|
||||
|
||||
let hash = to_int
|
||||
let (=) = equal
|
||||
let (<>) x y = compare x y <> 0
|
||||
let (<) x y = compare x y < 0
|
||||
let (<=) x y = compare x y <= 0
|
||||
@ -23,8 +35,9 @@ let (>) x y = compare x y > 0
|
||||
let min x y = if x <= y then x else y
|
||||
let max x y = if x <= y then y else x
|
||||
|
||||
let add = Int64.add
|
||||
let diff = Int64.sub
|
||||
let min_value = min_int
|
||||
let epoch = 0L
|
||||
let max_value = max_int
|
||||
|
||||
let now () = Int64.of_float (Unix.gettimeofday ())
|
||||
|
||||
@ -70,7 +83,7 @@ let rfc_encoding =
|
||||
"timestamp" @@
|
||||
describe
|
||||
~title:
|
||||
"RFC 339 formatted timestamp"
|
||||
"RFC 3339 formatted timestamp"
|
||||
~description:
|
||||
"A date in human readble form as specified in RFC 3339." @@
|
||||
conv
|
||||
@ -113,3 +126,9 @@ let make_timed data = {
|
||||
}
|
||||
|
||||
let pp_hum ppf t = Format.pp_print_string ppf (to_notation t)
|
||||
end
|
||||
|
||||
include T
|
||||
module Set = Set.Make(T)
|
||||
module Map = Map.Make(T)
|
||||
module Table = Hashtbl.Make(T)
|
||||
|
@ -9,6 +9,10 @@
|
||||
|
||||
type t
|
||||
|
||||
val min_value : t
|
||||
val epoch : t
|
||||
val max_value : t
|
||||
|
||||
val add : t -> int64 -> t
|
||||
val diff : t -> t -> int64
|
||||
|
||||
@ -46,3 +50,7 @@ type 'a timed_data = {
|
||||
val make_timed : 'a -> 'a timed_data
|
||||
|
||||
val timed_encoding : 'a Data_encoding.t -> 'a timed_data Data_encoding.t
|
||||
|
||||
module Set : Set.S with type elt = t
|
||||
module Map : Map.S with type key = t
|
||||
module Table : Hashtbl.S with type key = t
|
||||
|
Loading…
Reference in New Issue
Block a user