package core

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

See Time.Ofday.

include module type of struct include Core_kernel.Time_ns.Ofday end
type t = private Core_kernel.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_kernel.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.

type underlying = Core_kernel.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
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 variant t 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
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 Typerep_lib.Typerepable.S with type t := t
val typename_of_t : t Typerep_lib.Typename.t
include Core_kernel.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
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 ~compare: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

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

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 Base.Or_error.t
include Base.Comparator.S 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.Time_ns.Ofday.Replace_polymorphic_compare
include Base.Pretty_printer.S with type t := t
val pp : Base.Formatter.t -> t -> unit
include Core_kernel.Interfaces.Robustly_comparable 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 robustly_compare : t -> t -> int

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 Core_kernel.Interfaces.Stringable with type t := t
val of_string : string -> t
val to_string : t -> string
val 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
val start_of_day : t

Smallest valid ofday.

val start_of_next_day : t

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

val to_span_since_start_of_day : t -> Core_kernel.Time_ns.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.

val of_span_since_start_of_day_exn : Core_kernel.Time_ns.Span.t -> t
val of_span_since_start_of_day : Core_kernel.Time_ns.Span.t -> t
  • deprecated [since 2018-04] use [of_span_since_start_of_day_exn] instead

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.

val next : t -> t Base.Option.t

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

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

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

val diff : t -> t -> Core_kernel.Time_ns.Span.t

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

val small_diff : t -> t -> Core_kernel.Time_ns.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.

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

val to_sec_string : t -> Base.String.t

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

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

val to_millisecond_string : t -> Base.String.t

with milliseconds

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

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

val add_exn : t -> Core_kernel.Time_ns.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.

val sub_exn : t -> Core_kernel.Time_ns.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.

val now : zone:Core_kernel__.Zone.t -> t
val to_ofday : t -> Core_kernel.Time.underlying
  • deprecated [since 2019-01] use [to_ofday_float_round_nearest] or [to_ofday_float_round_nearest_microsecond]
val of_ofday : Core_kernel.Time.underlying -> t
  • deprecated [since 2019-01] use [of_ofday_float_round_nearest] or [of_ofday_float_round_nearest_microsecond]
val to_ofday_float_round_nearest : t -> Core_kernel.Time.underlying
val to_ofday_float_round_nearest_microsecond : t -> Core_kernel.Time.underlying
val of_ofday_float_round_nearest : Core_kernel.Time.underlying -> t
val of_ofday_float_round_nearest_microsecond : Core_kernel.Time.underlying -> t
module Zoned : sig ... end
module Option : sig ... end
OCaml

Innovation. Community. Security.