package timedesc

  1. Overview
  2. Docs
type t

Signed/directional span of time with nanosecond precision

exception Out_of_range

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_s_ns : t -> int64 * int

Yields pair (s, ns) where

  • 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.

ns is always >= 0 and < 1_000_000_000.

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.

Accessors

val get_s : t -> int64

Yields signed second of span, same as fst (to_s_ns _)

val get_ns_offset : t -> int

Yields the unsigned nanosecond offset, same as snd (to_s_ns _)

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 : Stdlib.Format.formatter -> t -> unit

Human friendly APIs

module For_human : sig ... end
OCaml

Innovation. Community. Security.