package core_unix

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Time_float_unix.SpanSource

include module type of Time.Span
Sourcetype underlying = Time.underlying

Span.t represents a span of time (e.g. 7 minutes, 3 hours, 12.8 days). The span may be positive or negative.

Sourcetype t = private underlying
include Bin_prot.Binable.S with type t := t
include Bin_prot.Binable.S_only_functions with type t := t
Sourceval bin_size_t : t Bin_prot.Size.sizer
Sourceval bin_write_t : t Bin_prot.Write.writer
Sourceval bin_read_t : t Bin_prot.Read.reader
Sourceval __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 variant t afterwards.

Sourceval bin_shape_t : Bin_prot.Shape.t
include Ppx_hash_lib.Hashable.S with type t := t
include Sexplib0.Sexpable.S with type t := t
Sourceval t_of_sexp : Sexplib0.Sexp.t -> t
Sourceval sexp_of_t : t -> Sexplib0.Sexp.t
Sourceval t_sexp_grammar : t Sexplib0.Sexp_grammar.t
Sourcemodule Parts = Time.Span.Parts
include Core.Interfaces.Comparable_binable with type t := t
include Base.Comparable.S with type t := t
include Base.Comparisons.S with type t := t
include Base.Comparisons.Infix with type t := t
Sourceval (>=) : t -> t -> bool
Sourceval (<=) : t -> t -> bool
Sourceval (=) : t -> t -> bool
Sourceval (>) : t -> t -> bool
Sourceval (<) : t -> t -> bool
Sourceval (<>) : t -> t -> bool
Sourceval equal : t -> t -> bool
Sourceval compare : t -> t -> int

compare t1 t2 returns 0 if t1 is equal to t2, a negative integer if t1 is less than t2, and a positive integer if t1 is greater than t2.

Sourceval min : t -> t -> t
Sourceval max : t -> t -> t
Sourceval 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 ~compare:ascending and List.sort ~cmp:descending, since they cause the list to be sorted in ascending or descending order, respectively.

Sourceval descending : t -> t -> int
Sourceval between : t -> low:t -> high:t -> bool

between t ~low ~high means low <= t <= high

Sourceval 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).

Sourceval clamp : t -> min:t -> max:t -> t Base.Or_error.t
include Base.Comparator.S with type t := t
Sourcetype comparator_witness = Time.Span.comparator_witness
Sourcemodule Replace_polymorphic_compare = Time.Span.Replace_polymorphic_compare
Sourcemodule Map = Time.Span.Map
Sourcemodule Set = Time.Span.Set
include Core.Comparable.With_zero with type t := t
include Base.Comparable.With_zero with type t := t
Sourceval is_positive : t -> bool
Sourceval is_non_negative : t -> bool
Sourceval is_negative : t -> bool
Sourceval is_non_positive : t -> bool
Sourceval sign : t -> Base.Sign.t

Returns Neg, Zero, or Pos in a way consistent with the above functions.

Sourceval validate_lbound : min:t Core.Maybe_bound.t -> t Validate.check
Sourceval validate_ubound : max:t Core.Maybe_bound.t -> t Validate.check
Sourceval validate_bound : min:t Core.Maybe_bound.t -> max:t Core.Maybe_bound.t -> t Validate.check
Sourceval validate_positive : t Validate.check
Sourceval validate_non_negative : t Validate.check
Sourceval validate_negative : t Validate.check
Sourceval validate_non_positive : t Validate.check
include Core.Interfaces.Hashable_binable with type t := t
include Ppx_hash_lib.Hashable.S with type t := t
Sourceval hash_fold_t : Base.Hash.state -> t -> Base.Hash.state
Sourceval hashable : t Base.Hashable.t
Sourcemodule Table = Time.Span.Table
Sourcemodule Hash_set = Time.Span.Hash_set
Sourcemodule Hash_queue = Time.Span.Hash_queue
include Diffable.S_atomic with type t := t
module Diff = Time.Span.Diff
include Base.Pretty_printer.S with type t := t
Sourceval pp : Base.Formatter.t -> t -> unit
include Core.Interfaces.Robustly_comparable with type t := t
Sourceval (>=.) : t -> t -> bool
Sourceval (<=.) : t -> t -> bool
Sourceval (=.) : t -> t -> bool
Sourceval (>.) : t -> t -> bool
Sourceval (<.) : t -> t -> bool
Sourceval (<>.) : t -> t -> bool
Sourceval robustly_compare : t -> t -> int
include Core.Quickcheck.S_range with type t := t
include Core.Quickcheck_intf.S with type t := t
Sourceval quickcheck_generator : t Base_quickcheck.Generator.t
Sourceval quickcheck_observer : t Base_quickcheck.Observer.t
Sourceval quickcheck_shrinker : t Base_quickcheck.Shrinker.t
Sourceval gen_incl : t -> t -> t Base_quickcheck.Generator.t

gen_incl lower_bound upper_bound produces values between lower_bound and upper_bound, inclusive. It uses an ad hoc distribution that stresses boundary conditions more often than a uniform distribution, while still able to produce any value in the range. Raises if lower_bound > upper_bound.

Sourceval gen_uniform_incl : t -> t -> t Base_quickcheck.Generator.t

gen_uniform_incl lower_bound upper_bound produces a generator for values uniformly distributed between lower_bound and upper_bound, inclusive. Raises if lower_bound > upper_bound.

Sourceval to_string : t -> Base.String.t

Time spans are denominated as a float suffixed by a unit of time; the valid suffixes are listed below:

d - days h - hours m - minutes s - seconds ms - milliseconds us - microseconds ns - nanoseconds

to_string and sexp_of_t use a mixed-unit format, which breaks the input span into parts and concatenates them in descending order of unit size. For example, pi days is rendered as "3d3h23m53.60527015815s". If the span is negative, a single "-" precedes the entire string. For extremely large (>10^15 days) or small (<1us) spans, a unit may be repeated to ensure the string conversion round-trips.

of_string and t_of_sexp accept any combination of (nonnegative float string)(unit of time suffix) in any order, without spaces, and sums up the durations of each of the parts for the magnitude of the span. The input may be prefixed by "-" for negative spans.

String and sexp conversions round-trip precisely, that is:

 Span.of_string (Span.to_string t) = t 
Sourceval of_string : Base.String.t -> t
values
Sourceval nanosecond : t
Sourceval microsecond : t
Sourceval millisecond : t
Sourceval second : t
Sourceval minute : t
Sourceval hour : t
Sourceval day : t
Sourceval robust_comparison_tolerance : t

10^-6 seconds, used in robustly comparable operators (<., >., =., ...) to determine equality

Sourceval zero : t
Sourceval create : ?sign:Core.Sign.t -> ?day:Base.Int.t -> ?hr:Base.Int.t -> ?min:Base.Int.t -> ?sec:Base.Int.t -> ?ms:Base.Int.t -> ?us:Base.Int.t -> ?ns:Base.Int.t -> Base.Unit.t -> t

?sign defaults to positive. Setting it to negative is equivalent to negating all the integers.

Sourceval to_parts : t -> Parts.t
converters

conversions to and from float

Sourceval of_ns : Base.Float.t -> t
Sourceval of_us : Base.Float.t -> t
Sourceval of_ms : Base.Float.t -> t
Sourceval of_sec : Base.Float.t -> t
Sourceval of_min : Base.Float.t -> t
Sourceval of_hr : Base.Float.t -> t
Sourceval of_day : Base.Float.t -> t
Sourceval to_ns : t -> Base.Float.t
Sourceval to_us : t -> Base.Float.t
Sourceval to_ms : t -> Base.Float.t
Sourceval to_sec : t -> Base.Float.t
Sourceval to_min : t -> Base.Float.t
Sourceval to_hr : t -> Base.Float.t
Sourceval to_day : t -> Base.Float.t

conversions from int

Sourceval of_int_ns : Base.Int.t -> t
Sourceval of_int_us : Base.Int.t -> t
Sourceval of_int_ms : Base.Int.t -> t
Sourceval of_int_sec : Base.Int.t -> t
Sourceval of_int_min : Base.Int.t -> t
Sourceval of_int_hr : Base.Int.t -> t
Sourceval of_int_day : Base.Int.t -> t

conversions from other size integer types for seconds

Sourceval of_int32_seconds : Core.Int32.t -> t
Sourceval of_int63_seconds : Core.Int63.t -> t
Sourceval to_int63_seconds_round_down_exn : t -> Core.Int63.t

to_int63_seconds_round_down_exn t returns the number of seconds represented by t, rounded down, raising if the result is not representable as an Int63.t.

Sourceval to_proportional_float : t -> Base.Float.t

The only condition to_proportional_float is supposed to satisfy is that for all t1, t2 : t: to_proportional_float t1 /. to_proportional_float t2 = t1 // t2.

Basic operations on spans

The arithmetic operations rely on the behavior of the underlying representation of a span. For example, if addition overflows with float-represented spans, the result is an infinite span; with fixed-width integer-represented spans, the result silently wraps around as in two's-complement arithmetic.

Sourceval (+) : t -> t -> t
Sourceval (-) : t -> t -> t
Sourceval abs : t -> t

absolute value

Sourceval neg : t -> t

negation

Sourceval scale : t -> Base.Float.t -> t
Sourceval (/) : t -> Base.Float.t -> t
Sourceval (//) : t -> t -> Base.Float.t
Sourceval next : t -> t

next t is the smallest representable span greater than t (and therefore representation-dependent)

Sourceval prev : t -> t

prev t is the largest representable span less than t (and therefore representation-dependent)

Sourceval to_short_string : t -> Base.String.t

to_short_string t pretty-prints approximate time span using no more than five characters if the span is positive, and six if the span is negative. Examples

  • "4h" = 4 hours
  • "5m" = 5 minutes
  • "4s" = 4 seconds
  • "10ms" = 10 milliseconds

only the most significant denomination is shown.

Sourceval to_unit_of_time : t -> Core.Unit_of_time.t

to_unit_of_time t = Day if abs t >= day, Hour if abs t >= hour, and so on down to Microsecond if abs t >= microsecond, and Nanosecond otherwise.

Sourceval of_unit_of_time : Core.Unit_of_time.t -> t

of_unit_of_time unit_of_time produces a t representing the corresponding span.

Sourceval to_string_hum : ?delimiter:Base.Char.t -> ?decimals:Base.Int.t -> ?align_decimal:Base.Bool.t -> ?unit_of_time:Core.Unit_of_time.t -> t -> Base.String.t

to_string_hum t ~delimiter ~decimals ~align_decimal ~unit_of_time formats t using the given unit of time, or the largest appropriate units if none is specified, among "d"=day, "h"=hour, "m"=minute, "s"=second, "ms"=millisecond, "us"=microsecond, or "ns"=nanosecond. The magnitude of the time span in the chosen unit is formatted by:

Float.to_string_hum ~delimiter ~decimals ~strip_zero:(not align_decimal)

If align_decimal is true, the single-character suffixes are padded with an extra space character. In combination with not stripping zeroes, this means that the decimal point will occur a fixed number of characters from the end of the string.

Sourceval randomize : ?state:Base.Random.State.t -> t -> percent:Core.Percent.t -> t

randomize t ~percent returns a span +/- percent * original span. Percent must be between 0% and 100% inclusive, and must be positive.

OCaml

Innovation. Community. Security.