Module type Time_ns_intf.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.
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 expectingTime_ns.t
.
Time_ns
silently ignores overflow.
Some reasons you might want want to actually prefer Time_ns.t
in certain cases:
- It has superior performance.
- It uses
int
s rather thanfloat
s internally, which makes certain things easier to reason about, sinceint
s respect a bunch of arithmetic identities thatfloat
s don't, e.g.,x + (y + z) = (x + y) + z
.
Neither Core.Time_ns
nor Core.Time
are available in Javascript.
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
).
See Core_kernel.Time_ns
for additional low level documentation.
include module type of sig ... end with module Span := Core__.Import.Time_ns.Span with module Ofday := Core__.Import.Time_ns.Ofday with module Stable := Core__.Import.Time_ns.Stable
module Span = Core_kernel__Time_ns.Span
module Ofday = Core_kernel__Time_ns.Ofday
type t
= Core_kernel__Time_ns.t
val hash_fold_t : Base.Hash.state -> t -> Base.Hash.state
val hash : t -> Base.Hash.hash_value
val typerep_of_t : t Typerep_lib.Std_internal.Typerep.t
val typename_of_t : t Typerep_lib.Typename.t
val bin_size_t : t Bin_prot.Size.sizer
val bin_write_t : t Bin_prot.Write.writer
val bin_read_t : t Bin_prot.Read.reader
val __bin_read_t__ : (int -> t) Bin_prot.Read.reader
val bin_shape_t : Bin_prot.Shape.t
val bin_writer_t : t Bin_prot.Type_class.writer
val bin_reader_t : t Bin_prot.Type_class.reader
val bin_t : t Bin_prot.Type_class.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 quickcheck_generator : t Base_quickcheck.Generator.t
val quickcheck_observer : t Base_quickcheck.Observer.t
val quickcheck_shrinker : t Base_quickcheck.Shrinker.t
val gen_incl : t -> t -> t Base_quickcheck.Generator.t
val gen_uniform_incl : t -> t -> t Base_quickcheck.Generator.t
val is_earlier : t -> than:t -> Core_kernel__.Import.bool
val is_later : t -> than:t -> Core_kernel__.Import.bool
val of_date_ofday : zone:Core_kernel__.Zone.t -> Core_kernel__.Time_intf.Date.t -> Ofday.t -> t
val of_date_ofday_precise : Core_kernel__.Time_intf.Date.t -> Ofday.t -> zone:Core_kernel__.Zone.t -> [ `Never of t | `Once of t | `Twice of t * t ]
val to_date_ofday : t -> zone:Core_kernel__.Zone.t -> Core_kernel__.Time_intf.Date.t * Ofday.t
val to_date_ofday_precise : t -> zone:Core_kernel__.Zone.t -> Core_kernel__.Time_intf.Date.t * Ofday.t * [ `Also_at of t | `Also_skipped of Core_kernel__.Time_intf.Date.t * Ofday.t | `Only ]
val to_date : t -> zone:Core_kernel__.Zone.t -> Core_kernel__.Time_intf.Date.t
val to_ofday : t -> zone:Core_kernel__.Zone.t -> Ofday.t
val reset_date_cache : Core_kernel__.Import.unit -> Core_kernel__.Import.unit
val convert : from_tz:Core_kernel__.Zone.t -> to_tz:Core_kernel__.Zone.t -> Core_kernel__.Time_intf.Date.t -> Ofday.t -> Core_kernel__.Time_intf.Date.t * Ofday.t
val utc_offset : t -> zone:Core_kernel__.Zone.t -> Span.t
val of_string : string -> t
val to_string : t -> string
val to_filename_string : t -> zone:Core_kernel__.Zone.t -> Core_kernel__.Import.string
val of_filename_string : Core_kernel__.Import.string -> zone:Core_kernel__.Zone.t -> t
val to_string_abs : t -> zone:Core_kernel__.Zone.t -> Core_kernel__.Import.string
val to_string_abs_trimmed : t -> zone:Core_kernel__.Zone.t -> Core_kernel__.Import.string
val to_string_abs_parts : t -> zone:Core_kernel__.Zone.t -> Core_kernel__.Import.string Core_kernel__.Import.list
val to_string_trimmed : t -> zone:Core_kernel__.Zone.t -> Core_kernel__.Import.string
val to_sec_string : t -> zone:Core_kernel__.Zone.t -> Core_kernel__.Import.string
val of_localized_string : zone:Core_kernel__.Zone.t -> Core_kernel__.Import.string -> t
val of_string_gen : default_zone:(Core_kernel__.Import.unit -> Core_kernel__.Zone.t) -> find_zone:(Core_kernel__.Import.string -> Core_kernel__.Zone.t) -> Core_kernel__.Import.string -> t
val to_string_iso8601_basic : t -> zone:Core_kernel__.Zone.t -> Core_kernel__.Import.string
val occurrence : [ `First_after_or_at | `Last_before_or_at ] -> t -> ofday:Ofday.t -> zone:Core_kernel__.Zone.t -> t
val epoch : t
val min_value_representable : t
val max_value_representable : t
val min_value_for_1us_rounding : t
val max_value_for_1us_rounding : t
val min_value : t
val max_value : t
val now : Core_kernel__.Import.unit -> t
val add : t -> Span.t -> t
val add_saturating : t -> Span.t -> t
val sub_saturating : t -> Span.t -> t
val sub : t -> Span.t -> t
val next : t -> t
val prev : 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_int63_ns_since_epoch : t -> Core_kernel.Int63.t
val of_int63_ns_since_epoch : Core_kernel.Int63.t -> t
val to_int_ns_since_epoch : t -> Core_kernel__.Import.int
val of_int_ns_since_epoch : Core_kernel__.Import.int -> t
val next_multiple : ?can_equal_after:Core_kernel__.Import.bool -> base:t -> after:t -> interval:Span.t -> Core_kernel__.Import.unit -> t
val prev_multiple : ?can_equal_before:Core_kernel__.Import.bool -> base:t -> before:t -> interval:Span.t -> Core_kernel__.Import.unit -> t
val random : ?state:Core_kernel__.Import.Random.State.t -> Core_kernel__.Import.unit -> t
val of_time : Core_kernel__.Time_float.t -> t
val to_time : t -> Core_kernel__.Time_float.t
val to_time_float_round_nearest : t -> Core_kernel__.Time_float.t
val to_time_float_round_nearest_microsecond : t -> Core_kernel__.Time_float.t
val of_time_float_round_nearest : Core_kernel__.Time_float.t -> t
val of_time_float_round_nearest_microsecond : Core_kernel__.Time_float.t -> t
module Utc = Core_kernel__Time_ns.Utc
module Stable = Core_kernel__Time_ns.Stable
val arg_type : t Core_kernel.Command.Arg_type.t
module Option : sig ... end
Option.t
is liket option
, except that the value is immediate. This module should mainly be used to avoid allocations.
String conversions use the local timezone by default. Sexp conversions use get_sexp_zone ()
by default, which can be overridden by calling set_sexp_zone
. These default time zones are used when writing a time, and when reading a time with no explicit zone or UTC offset.
Sexps and strings display the date, ofday, and UTC offset of t
relative to the appropriate time zone.
include Core__.Import.Identifiable with type t := t
include Bin_prot.Binable.S with type t := t
include Bin_prot.Binable.S_only_functions with type t := t
val bin_size_t : t Bin_prot.Size.sizer
val bin_write_t : t Bin_prot.Write.writer
val bin_read_t : t Bin_prot.Read.reader
val __bin_read_t__ : (int -> t) Bin_prot.Read.reader
This function only needs implementation if
t
exposed to be a polymorphic variant. Despite what the type reads, this does *not* produce a function after reading; instead it takes the constructor tag (int) before reading and reads the rest of the variantt
afterwards.
val bin_shape_t : Bin_prot.Shape.t
val bin_writer_t : t Bin_prot.Type_class.writer
val bin_reader_t : t Bin_prot.Type_class.reader
val bin_t : t Bin_prot.Type_class.t
val hash_fold_t : Base.Hash.state -> t -> Base.Hash.state
val hash : t -> Base.Hash.hash_value
include Ppx_sexp_conv_lib.Sexpable.S with type t := t
val t_of_sexp : Sexplib0.Sexp.t -> t
val sexp_of_t : t -> Sexplib0.Sexp.t
include Core_kernel.Identifiable.S_common with type t := t
val compare : t -> t -> Core_kernel__.Import.int
val hash_fold_t : Base.Hash.state -> t -> Base.Hash.state
val hash : t -> Base.Hash.hash_value
val sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
include Core_kernel__.Import.Stringable.S with type t := t
include Core_kernel__.Import.Pretty_printer.S with type t := t
val pp : Base.Formatter.t -> t -> unit
include Core_kernel.Comparable.S_binable with type t := t
include Core_kernel__.Comparable_intf.S_common
include Base.Comparable.S
include Base__.Comparable_intf.Polymorphic_compare
val ascending : t -> t -> int
ascending
is identical tocompare
.descending x y = ascending y x
. These are intended to be mnemonic when used likeList.sort ~compare:ascending
andList.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
between t ~low ~high
meanslow <= t <= high
val clamp_exn : t -> min:t -> max:t -> t
clamp_exn t ~min ~max
returnst'
, the closest value tot
such thatbetween t' ~low:min ~high:max
is true.Raises if
not (min <= max)
.
val clamp : t -> min:t -> max:t -> t Base.Or_error.t
include Base.Comparator.S with type t := t
val comparator : (t, comparator_witness) Base.Comparator.comparator
include Base__.Comparable_intf.Validate with type t := t
val validate_lbound : min:t Base.Maybe_bound.t -> t Base.Validate.check
val validate_ubound : max:t Base.Maybe_bound.t -> t Base.Validate.check
val validate_bound : min:t Base.Maybe_bound.t -> max:t Base.Maybe_bound.t -> t Base.Validate.check
module Replace_polymorphic_compare : Core_kernel__.Comparable_intf.Polymorphic_compare with type t := t
include Core_kernel__.Comparable_intf.Map_and_set_binable with type t := t with type comparator_witness := comparator_witness
include Core_kernel.Comparator.S with type t := t
val comparator : (t, comparator_witness) Core_kernel.Comparator.comparator
module Map : Core_kernel.Map.S_binable with type Key.t = t with type Key.comparator_witness = comparator_witness
module Set : Core_kernel.Set.S_binable with type Elt.t = t with type Elt.comparator_witness = comparator_witness
include Core_kernel.Hashable.S_binable with type t := t
val hash_fold_t : Base.Hash.state -> t -> Base.Hash.state
val hash : t -> Base.Hash.hash_value
val hashable : t Core_kernel.Hashtbl.Hashable.t
module Table : Core_kernel.Hashtbl.S_binable with type key = t
module Hash_set : Core_kernel.Hash_set.S_binable with type elt = t
module Hash_queue : Core_kernel.Hash_queue.S with type key = t
module Zone : module type of Core__.Import_time.Time.Zone with type Zone.t = Core__.Import_time.Time.Zone.t
val get_sexp_zone : unit -> Zone.t
val set_sexp_zone : Zone.t -> unit
val t_of_sexp_abs : Core__.Import.Sexp.t -> t
t_of_sexp_abs sexp
ast_of_sexp
, but demands thatsexp
indicate the timezone the time is expressed in.
val sexp_of_t_abs : t -> zone:Zone.t -> Core__.Import.Sexp.t
val of_date_ofday_zoned : Core__.Import.Date.t -> Ofday.Zoned.t -> t
Conversion functions that involved Ofday.Zoned.t, exactly analogous to the conversion functions that involve Ofday.t
val to_date_ofday_zoned : t -> zone:Core__.Import_time.Time.Zone.t -> Core__.Import.Date.t * Ofday.Zoned.t
val to_ofday_zoned : t -> zone:Core__.Import_time.Time.Zone.t -> Ofday.Zoned.t
val to_string_fix_proto : [ `Utc | `Local ] -> t -> string
val of_string_fix_proto : [ `Utc | `Local ] -> string -> t
val of_string_abs : string -> t
This is like
of_string
except that if the string doesn't specify the zone then it raises rather than assume the local timezone.
val of_string_gen : if_no_timezone:[ `Fail | `Local | `Use_this_one of Zone.t ] -> string -> t
of_string_gen ~if_no_timezone s
attempts to parses
to at
. Ifs
doesn't supply a time zoneif_no_timezone
is consulted.
val pause : Span.t -> unit
pause span
sleeps forspan
time.
val interruptible_pause : Span.t -> [ `Ok | `Remaining of Span.t ]
interruptible_pause span
sleeps forspan
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__.Import.never_returns
pause_forever
sleeps indefinitely.
module Stable : sig ... end