package core

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

Module Time_ns.OfdaySource

Sourcetype t = private Int63.t

t is immediate on 64bit boxes and so plays nicely with the GC write barrier.

String and sexp output takes the form 'HH:MM:SS.sssssssss'; see Core.Ofday_intf for accepted input. If input includes more than 9 decimal places in seconds, rounds to the nearest nanosecond, with the midpoint rounded up. Allows 60.sss... seconds for leap seconds but treats it as exactly 60s regardless of fractional part.

Sourcetype underlying = Int63.t

Time of day.

t represents a clock-face time of day. Usually this is equivalent to a time-offset from midnight, and each t occurs exactly once in each calendar day. However, when daylight saving time begins or ends, some clock face times (and therefore t's) can occur more than once per day or not at all, and e.g. 04:00 can occur three or five hours after midnight, so knowing your current offset from midnight is *not* in general equivalent to knowing the current t.

(See Zone for tools to help you cope with DST.)

There is one nonstandard representable value, start_of_next_day, which can be thought of as "24:00:00" in 24-hour time. It is essentially "00:00:00" on the next day. By having this value, we allow comparisons against a strict upper bound on t values. However, it has some odd properties; for example, Time.of_date_ofday ~zone date start_of_next_day |> Time.to_date ~zone yields a different date.

Any ofday will satisfy start_of_day <= ofday <= start_of_next_day.

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 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
include 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
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

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.

val min : t -> t -> t
val 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
Sourceval validate_lbound : min:t Maybe_bound.t -> t Validate.check
Sourceval validate_ubound : max:t Maybe_bound.t -> t Validate.check
Sourceval validate_bound : min:t Maybe_bound.t -> max:t Maybe_bound.t -> t Validate.check
include 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 : Hashtbl.S_binable with type key = t
Sourcemodule Hash_set : Hash_set.S_binable with type elt = t
Sourcemodule Hash_queue : Hash_queue.S with type key = t
include Base.Pretty_printer.S with type t := t
Sourceval pp : Base.Formatter.t -> t -> unit
include 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 Quickcheck.S_range with type t := t
include 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.

of_string supports and correctly interprets 12h strings with the following suffixes:

"A", "AM", "A.M.", "A.M"
"P", "PM", "P.M.", "P.M"

as well as the lowercase and space-prefixed versions of these suffixes.

of_string also fully supports 24h wall-clock times.

to_string only produces the 24h format.

include Interfaces.Stringable with type t := t
Sourceval of_string : string -> t
Sourceval to_string : t -> string
Sourceval create : ?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
Sourceval to_parts : t -> Span.Parts.t
Sourceval start_of_day : t

Smallest valid ofday.

Sourceval start_of_next_day : t

Largest representable ofday; see notes above on how start_of_next_day behaves differently from other ofday values.

Sourceval to_span_since_start_of_day : t -> Span.t

Note that these names are only really accurate on days without DST transitions. When clocks move forward or back, of_span_since_start_of_day_exn s will not necessarily occur s after that day's midnight.

Sourceval of_span_since_start_of_day_exn : Span.t -> t
Sourceval of_span_since_start_of_day : Span.t -> t
  • deprecated [since 2018-04] use [of_span_since_start_of_day_exn] instead
Sourceval span_since_start_of_day_is_valid : Span.t -> Base.Bool.t

Reports whether a span represents a valid time since the start of the day, i.e. whether of_span_since_start_of_day_exn span would succeed.

Sourceval of_span_since_start_of_day_unchecked : Span.t -> t

of_span_since_start_of_day_unchecked does not validate that the Span represents a valid Ofday.

Behavior of other Ofday accessors is unspecified, but still safe (e.g., won't segfault), if the input does not satisfy span_since_start_of_day_is_valid.

Sourceval add : t -> Span.t -> t Base.Option.t

add t s shifts the time of day t by the span s. It returns None if the result is not in the same 24-hour day.

Sourceval sub : t -> Span.t -> t Base.Option.t
Sourceval next : t -> t Base.Option.t

next t return the next t (next t > t) or None if t = end of day.

Sourceval prev : t -> t Base.Option.t

prev t return the previous t (prev t < t) or None if t = start of day.

Sourceval diff : t -> t -> Span.t

diff t1 t2 returns the difference in time between two ofdays, as if they occurred on the same 24-hour day.

Sourceval small_diff : t -> t -> Span.t

Returns the time-span separating the two of-days, ignoring the hour information, and assuming that the of-days represent times that are within a half-hour of each other. This is useful for comparing two ofdays in unknown time-zones.

Sourceval to_string_trimmed : t -> Base.String.t

Trailing groups of zeroes are trimmed such that the output is printed in terms of the smallest non-zero units among nanoseconds, microseconds, milliseconds, or seconds; or minutes if all of the above are zero.

Sourceval to_sec_string : t -> Base.String.t

HH:MM:SS, without any subsecond components. Seconds appear even if they are zero.

Sourceval of_string_iso8601_extended : ?pos:Base.Int.t -> ?len:Base.Int.t -> Base.String.t -> t

24-hour times according to the ISO 8601 standard. This function can raise.

Sourceval to_millisecond_string : t -> Base.String.t

with milliseconds

Sourceval to_millisec_string : t -> Base.String.t
  • deprecated [since 2018-04] use [to_millisecond_string] instead
Sourceval approximate_end_of_day : t

The largest representable value below start_of_next_day, i.e. one nanosecond before midnight.

Sourceval add_exn : t -> Span.t -> t

add_exn t span shifts the time of day t by span. It raises if the result is not in the same 24-hour day. Daylight savings shifts are not accounted for.

Sourceval sub_exn : t -> Span.t -> t

sub_exn t span shifts the time of day t back by span. It raises if the result is not in the same 24-hour day. Daylight savings shifts are not accounted for.

Sourceval every : Span.t -> start:t -> stop:t -> t Base.List.t Or_error.t

every span ~start ~stop returns a sorted list of all ts that can be expressed as start + (i * span) without overflow, and satisfying t >= start && t <= stop.

If span <= Span.zero || start > stop, returns an Error.

The result never crosses the midnight boundary. Constructing a list crossing midnight, e.g. every hour from 10pm to 2am, requires multiple calls to every.

Sourceval to_microsecond_string : t -> Base.String.t
Sourceval arg_type : [ `Use_Time_ns_unix ]
  • deprecated [since 2021-03] Use [Time_ns_unix]
Sourceval now : [ `Use_Time_ns_unix ]
  • deprecated [since 2021-03] Use [Time_ns_unix]
Sourceval of_ofday_float_round_nearest : [ `Use_Time_ns_unix ]
  • deprecated [since 2021-03] Use [Time_ns_unix]
Sourceval of_ofday_float_round_nearest_microsecond : [ `Use_Time_ns_unix ]
  • deprecated [since 2021-03] Use [Time_ns_unix]
Sourceval to_ofday_float_round_nearest : [ `Use_Time_ns_unix ]
  • deprecated [since 2021-03] Use [Time_ns_unix]
Sourceval to_ofday_float_round_nearest_microsecond : [ `Use_Time_ns_unix ]
  • deprecated [since 2021-03] Use [Time_ns_unix]
Sourcemodule Option : sig ... end
Sourcemodule Zoned : sig ... end
OCaml

Innovation. Community. Security.