package timedesc

  1. Overview
  2. Docs
type t = private {
  1. s : int64;
  2. ns : int;
}

Signed/directional span of time expressed as a tuple of (s, ns)

  • s is the signed second of the span
  • ns is the unsigned nanosecond offset

The actual span represented is defined as s * 10^9 + ns in nanosecond, regardless of the sign of s

Order is defined using lexicographic order, i.e. lt x y iff. x.s < y.s || (x.s = y.s && x.ns < y.ns)

exception Out_of_range
module For_human : sig ... end

Constants

val ns_count_in_s : int
val ns_count_in_s_float : float
val zero : t

Constructors

val make : ?s:int64 -> ?ns:int -> unit -> t

s defaults to 0L, ns defaults to 0

ns may be negative, and is normalized during construction

Interpretation of provided input is still s + ns, i.e. if you wish to represent "negative (1 second and 500 nanosecond)", then the call could look like make ~s:(-1L) ~ns:(-500)

  • raises Out_of_range

    if the value cannot be represented even after normalization

val make_small : ?s:int -> ?ns:int -> unit -> t

Wrapper around make

Conversion

val to_float_s : t -> float

Returns span in seconds, fraction represents subsecond span.

Representation is the same as result from Unix.gettimeofday.

val of_float_s : float -> t

Convert from span in seconds, fraction represents subsecond span

Representation is the same as result from Unix.gettimeofday.

Comparison

val equal : t -> t -> bool
val lt : t -> t -> bool
val le : t -> t -> bool
val gt : t -> t -> bool
val ge : t -> t -> bool
val compare : t -> t -> int

Arithmetic

val add : t -> t -> t
val sub : t -> t -> t
val succ : t -> t
val pred : t -> t
val neg : t -> t
val abs : t -> t
val max : t -> t -> t
val min : t -> t -> t
val ceil : t -> t

Rounds up to nearest second

val floor : t -> t

Rounds down to nearest second

val round : t -> t

Rounds to nearest second

For round x

  • if x.ns >= 500_000_000, then round x = ceil x
  • otherwise round x = floor x
val (<) : t -> t -> bool
val (<=) : t -> t -> bool
val (>) : t -> t -> bool
val (>=) : t -> t -> bool
val (=) : t -> t -> bool
val (<>) : t -> t -> bool
val (-) : t -> t -> t
val (+) : t -> t -> t

Pretty printing

val to_string : t -> string
val pp : Format.formatter -> t -> unit
val to_sexp : t -> CCSexp.t
val to_sexp_string : t -> string
val of_sexp : CCSexp.t -> (t, string) result
val of_sexp_string : string -> (t, string) result
val pp_sexp : Format.formatter -> t -> unit
OCaml

Innovation. Community. Security.