Up

Module Time_ns

An absolute point in time, more efficient and precise than the float-based Time, but representing a narrower range of times.

This module represents absolute times with nanosecond precision, approximately between the years 1823 and 2116 CE.

NOTE: you should normally default to using Time instead of this module. The reasons are:

  • Many functions around our libraries expect Time.t values, so it will likely be much more convenient for you.
  • It leads to greater consistency across different codebases. It would be bad to end up with half our libraries expecting Time.t and the other half expecting Time_ns.t.

Some reasons you might want want to actually prefer Time_ns.t in certain cases:

  • It has superior performance.
  • It uses ints rather than floats internally, which makes certain things easier to reason about, since ints respect a bunch of arithmetic identities that floats don't, e.g., x + (y + z) = (x + y) + z.
  • It is available on non-UNIX platforms, including Javascript via js_of_ocaml.

All in all, it would have been nice to have chosen Time_ns.t to begin with, but we're unlikely to flip everything to Time_ns.t in the short term (see comment at the end of time_ns.ml).

Signature

val typerep_of_t : t Typerep_lib.Std.Typerep.t
val typename_of_t : t Typerep_lib.Std.Typename.t
module Span : sig .. end
module Option : sig .. end
module Ofday : sig .. end
include Core_kernel.Std.Identifiable with type t := t
type t
val t_of_sexp : Sexplib.Sexp.t -> t
val sexp_of_t : t -> Sexplib.Sexp.t
val bin_read_t : t Bin_prot.Read.reader
val __bin_read_t__ : (int -> t) Bin_prot.Read.reader
val bin_reader_t : t Bin_prot.Type_class.reader
val bin_size_t : t Bin_prot.Size.sizer
val bin_write_t : t Bin_prot.Write.writer
val bin_writer_t : t Bin_prot.Type_class.writer
include Core_kernel.Stringable.S with type t := t
type t
val of_string : string -> t
val to_string : t -> string
include Core_kernel.Comparable.S_binable with type t := t
include Comparable_intf.S_common
include Comparable_intf.Polymorphic_compare
include Polymorphic_compare_intf.Infix
type t
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 equal : t -> t -> bool
val compare : t -> t -> int
val min : t -> t -> t
val max : t -> t -> t
val ascending : t -> t -> int

ascending is identical to compare. descending x y = ascending y x. These are intended to be mnemonic when used like List.sort ~cmp:ascending and List.sort ~cmp:descending, since they cause the list to be sorted in ascending or descending order, respectively.

val descending : t -> t -> int
val between : t -> low:t -> high:t -> bool
val clamp_exn : t -> min:t -> max:t -> t

clamp_exn t ~min ~max returns t', the closest value to t such that between t' ~low:min ~high:max is true.

Raises if not (min <= max).

val clamp : t -> min:t -> max:t -> t Or_error.t
include Comparator.S with type t := t
type t
type comparator_witness
include Comparable_intf.Validate with type t := t
type t
val validate_lbound : min:t Maybe_bound.t -> t Validate.check
val validate_ubound : max:t Maybe_bound.t -> t Validate.check
val validate_bound : min:t Maybe_bound.t -> max:t Maybe_bound.t -> t Validate.check
include Comparable_intf.Map_and_set_binable with type t := t with type comparator_witness := comparator_witness
type t
include Comparator.S with type t := t
type t
type comparator_witness
include Core_kernel.Hashable.S_binable with type t := t
type t
val hash : t -> int
module Table : Hashable.Hashtbl.S_binable with type key = t
include Core_kernel.Pretty_printer.S with type t := t
type t
val pp : Format.formatter -> t -> unit
val epoch : t

Unix epoch (1970-01-01 00:00:00 UTC)

val min_value : t
val max_value : t
val now : unit -> t
val add : t -> Span.t -> t
val sub : t -> Span.t -> t
val diff : t -> t -> Span.t
val abs_diff : t -> t -> Span.t
val to_span_since_epoch : t -> Span.t
val of_span_since_epoch : Span.t -> t
val to_time : t -> Time.t
val of_time : Time.t -> t
val to_string_fix_proto : [
| `Utc
| `Local
] -> t -> string
val of_string_fix_proto : [
| `Utc
| `Local
] -> string -> t
val to_string_abs : t -> zone:Zone.t -> string
val of_string_abs : string -> t
val to_int63_ns_since_epoch : t -> Core_kernel.Std.Int63.t
val of_int63_ns_since_epoch : Core_kernel.Std.Int63.t -> t
val to_int_ns_since_epoch : t -> int

Will raise on 32-bit platforms. Consider to_int63_ns_since_epoch instead.

val of_int_ns_since_epoch : int -> t
val next_multiple : ?can_equal_after:bool -> base:t -> after:t -> interval:Span.t -> unit -> t

See Core_kernel.Time_ns

val of_date_ofday : zone:Zone.t -> Date.t -> Ofday.t -> t
val to_date : t -> zone:Zone.t -> Date.t
val occurrence : [
| `First_after_or_at
| `Last_before_or_at
] -> t -> ofday:Ofday.t -> zone:Zone.t -> t
val pause : Span.t -> unit

pause span sleeps for span time.

val interruptible_pause : Span.t -> [
| `Ok
| `Remaining of Span.t
]

interruptible_pause span sleeps for span time unless interrupted (e.g. by delivery of a signal), in which case the remaining unslept portion of time is returned.

val pause_forever : unit -> Core_kernel.Std.never_returns

pause_forever sleeps indefinitely.

module Stable : sig .. end
val random : unit -> t