package timedesc

  1. Overview
  2. Docs

Timestamp specific functions

type t = timestamp

Constants

val min_val : t
val max_val : t

Now

val now : unit -> t

Re-export from Span

Conversion

val to_s_ns : t -> int64 * int
val to_float_s : t -> float

Returns span in seconds, fraction represents subsecond span.

Representation is the same as result from Unix.gettimeofday.

val of_float_s : float -> t

Convert from span in seconds, fraction represents subsecond span

Representation is the same as result from Unix.gettimeofday.

Accessors

val get_s : t -> int64
val get_ns_offset : t -> int

Comparison

val equal : t -> t -> bool
val lt : t -> t -> bool
val le : t -> t -> bool
val gt : t -> t -> bool
val ge : t -> t -> bool
val compare : t -> t -> int

Arithmetic

val add : t -> t -> t
val sub : t -> t -> t
val succ : t -> t
val pred : t -> t
val neg : t -> t
val abs : t -> t
val max : t -> t -> t
val min : t -> t -> t
val ceil : t -> t
val floor : t -> t
val round : 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 (-) : t -> t -> t
val (+) : t -> t -> t

Pretty printing

val pp : ?display_using_tz:Time_zone.t -> ?format:string -> unit -> Stdlib.Format.formatter -> t -> unit

Pretty printing for timestamp.

Follows same format string rules and default format string as pp.

val to_string : ?display_using_tz:Time_zone.t -> ?format:string -> timestamp -> string
val pp_rfc3339 : ?frac_s:int -> unit -> Stdlib.Format.formatter -> t -> unit

Pretty prints according to RFC3339, e.g. 2020-01-20T13:00:00.0001+10.

frac_s determines the number of fractional digits to include.

  • raises Invalid_argument

    if frac_s < 0 || frac_s > 9

val pp_rfc3339_milli : Stdlib.Format.formatter -> t -> unit
val pp_rfc3339_micro : Stdlib.Format.formatter -> t -> unit
val pp_rfc3339_nano : Stdlib.Format.formatter -> t -> unit
val to_rfc3339 : ?frac_s:int -> t -> string
val to_rfc3339_milli : t -> string
val to_rfc3339_micro : t -> string
val to_rfc3339_nano : t -> string
val pp_iso8601 : ?frac_s:int -> unit -> Stdlib.Format.formatter -> t -> unit

Alias to pp_rfc3339

val pp_iso8601_milli : Stdlib.Format.formatter -> t -> unit
val pp_iso8601_micro : Stdlib.Format.formatter -> t -> unit
val pp_iso8601_nano : Stdlib.Format.formatter -> t -> unit
val to_iso8601 : ?frac_s:int -> t -> string

Alias to to_rfc3339

val to_iso8601_milli : t -> string
val to_iso8601_micro : t -> string
val to_iso8601_nano : t -> string
val pp_rfc9110 : Stdlib.Format.formatter -> t -> unit

Warning: Subsecond value is truncated

val to_rfc9110 : t -> string

Warning: Subsecond value is truncated

val pp_http : Stdlib.Format.formatter -> t -> unit

Alias to pp_rfc9110

val to_http : t -> string

Alias to to_rfc9110

Parsing

val of_iso8601 : string -> (t, string) Stdlib.result

Parses a subset of ISO8601, up to 9 fractional digits for second (nanosecond precision).

If more than 9 fractional digits are provided, then only the first 9 digits are used, i.e. no rounding.

val of_iso8601_exn : string -> t
val of_rfc9110 : string -> (t, string) Stdlib.result
val of_rfc9110_exn : string -> t
val of_http : string -> (t, string) Stdlib.result

Alias to of_rfc9110

val of_http_exn : string -> t

Alias to of_rfc9110_exn

OCaml

Innovation. Community. Security.