package core

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
include module type of struct include Core_kernel.Time.Zone end

User-friendly interface

type t

The type of a time-zone.

bin_io and sexp representations of Zone.t are the name of the zone, and not the full data that is read from disk when Zone.find is called. The full Zone.t is reconstructed on the receiving/reading side by reloading the zone file from disk. Any zone name that is accepted by find is acceptable in the bin_io and sexp representations.

include sig ... end
val input_tz_file : zonename:Base.String.t -> filename:Base.String.t -> t

input_tz_file ~zonename ~filename read in filename and return t with name t = zonename

val name : t -> Base.String.t
val original_filename : t -> Base.String.t Base.Option.t

original_filename t return the filename t was loaded from (if any)

val digest : t -> Core_kernel.Md5.t Base.Option.t

digest t return the MD5 digest of the file the t was created from (if any)

val reset_transition_cache : t -> Base.Unit.t

For performance testing only; reset_transition_cache t resets an internal cache in t used to speed up repeated lookups of the same clock shift transition.

A time zone index refers to a range of times delimited by DST transitions at one or both ends. Every time belongs to exactly one such range. The times of DST transitions themselves belong to the range for which they are the lower bound.

Gets the index of a time.

val index_offset_from_utc_exn : t -> Index.t -> Core_kernel.Core_kernel_private.Time_float0.Span.t

Gets the UTC offset of times in a specific range.

This can raise if you use an Index.t that is out of bounds for this t.

val index_abbreviation_exn : t -> Index.t -> Base.String.t

index_abbreviation_exn t index returns the abbreviation name (such as EDT, EST, JST) of given zone t for the range of index. This string conversion is one-way only, and cannot reliably be turned back into a t. This function reads and writes the zone's cached index. Raises if index is out of bounds for t.

val index_has_prev_clock_shift : t -> Index.t -> Base.Bool.t

Accessors for the DST transitions delimiting the start and end of a range, if any. The _exn accessors raise if there is no such transition. These accessors are split up to increase performance and improve allocation; they are intended as a low-level back-end for commonly-used time conversion functions. See Time.Zone and Time_ns.Zone for higher-level accessors that return an optional tuple for clock shifts in either direction.

val index_prev_clock_shift_time_exn : t -> Index.t -> Core_kernel.Core_kernel_private.Time_float0.t
val index_prev_clock_shift_amount_exn : t -> Index.t -> Core_kernel.Core_kernel_private.Time_float0.Span.t
val index_has_next_clock_shift : t -> Index.t -> Base.Bool.t
val index_next_clock_shift_time_exn : t -> Index.t -> Core_kernel.Core_kernel_private.Time_float0.t
val index_next_clock_shift_amount_exn : t -> Index.t -> Core_kernel.Core_kernel_private.Time_float0.Span.t
val abbreviation : t -> Core_kernel.Core_kernel_private.Time_float0.t -> Base.String.t

abbreviation t time returns the abbreviation name (such as EDT, EST, JST) of given zone t at time. This string conversion is one-way only, and cannot reliably be turned back into a t. This function reads and writes the zone's cached index.

absolute_time_of_relative_time and relative_time_of_absolute_time convert times between absolute (time from epoch in UTC) and relative (shifted according to time zone and daylight savings) forms. These are low level functions not intended for most clients. These functions read and write the zone's cached index.

Takes a Time.t and returns the next Time.t strictly after it, if any, that the time zone UTC offset changes, and by how much it does so.

As next_clock_shift, but *at or before* the given time.

include Core_kernel.Identifiable.S with type t := t
include sig ... end
val bin_t : t Bin_prot.Type_class.t
val bin_read_t : t Bin_prot.Read.reader
val __bin_read_t__ : (Base.Int.t -> 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
val bin_shape_t : Bin_prot.Shape.t
val t_of_sexp : Ppx_sexp_conv_lib.Sexp.t -> t
include Core_kernel.Identifiable.S_common with type t := t
include sig ... end
val sexp_of_t : t -> Ppx_sexp_conv_lib.Sexp.t
val of_string : string -> t
val to_string : t -> string
val pp : Base__.Formatter.t -> t -> unit
include Core_kernel.Comparable.S_binable with type t := t
include Base.Comparable.S 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
val min : t -> t -> t
val max : t -> t -> t
val ascending : t -> t -> int
val descending : t -> t -> int
val between : t -> low:t -> high:t -> bool
val clamp_exn : t -> min:t -> max:t -> t
val clamp : t -> min:t -> max:t -> t Base__.Or_error.t
type comparator_witness
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 : sig ... end
module Map : sig ... end
module Set : sig ... end
include Core_kernel.Hashable.S_binable with type t := t
include sig ... end
val hash_fold_t : Ppx_hash_lib.Std.Hash.state -> t -> Ppx_hash_lib.Std.Hash.state
val hash : t -> Ppx_hash_lib.Std.Hash.hash_value
val hashable : t Core_kernel__.Hashtbl.Hashable.t
module Table : sig ... end
module Hash_set : sig ... end
module Hash_queue : sig ... end
val find : string -> t option

find name looks up a t by its name and returns it. This also accepts some aliases, including:

  • chi -> America/Chicago
  • nyc -> America/New_York
  • hkg -> Asia/Hong_Kong
  • lon -> Europe/London
  • tyo -> Asia/Tokyo
val find_exn : string -> t
val local : t Core_kernel.Lazy.t

local is the machine's local timezone, as determined from the TZ environment variable or the /etc/localtime file. It is computed from the state of the process environment and on-disk tzdata database at some unspecified moment prior to its first use, so its value may be unpredictable if that state changes during program operation. Arguably, changing the timezone of a running program is a problematic operation anyway -- most people write code assuming the clock doesn't suddenly jump several hours without warning.

Note that any function using this timezone can throw an exception if the TZ environment variable is misconfigured or if the appropriate timezone files can't be found because of the way the box is configured. We don't sprinkle _exn all over all the names in this module because such misconfiguration is quite rare.

val likely_machine_zones : string list Stdlib.Pervasives.ref

likely_machine_zones is a list of zone names that will be searched first when trying to determine the machine zone of a box. Setting this to a likely set of zones for your application will speed the very first use of the local timezone.

val of_utc_offset : hours:int -> t

of_utc_offset offset returns a timezone with a static UTC offset (given in hours).

val utc : t

utc the UTC time zone. Included for convenience

val initialized_zones : unit -> (string * t) list

initialized_zones () returns a sorted list of time zone names that have been loaded from disk thus far.

Low-level functions

The functions below are lower level and should be used more rarely.

val init : unit -> unit

init () pre-load all available time zones from disk, this function has no effect if it is called multiple times. Time zones will otherwise be loaded at need from the disk on the first call to find/find_exn.

OCaml

Innovation. Community. Security.