package timere

  1. Overview
  2. Docs

Module Timere.Date_timeSource

Sourcetype tz_info = [
  1. | `Tz_only of Time_zone.t
  2. | `Tz_offset_s_only of int
  3. | `Tz_and_tz_offset_s of Time_zone.t * int
]
Sourceval tz_offset_s_of_tz_info : tz_info -> int option
Sourcetype t = private {
  1. year : int;
  2. month : month;
  3. day : int;
  4. hour : int;
  5. minute : int;
  6. second : int;
  7. ns : int;
  8. tz_info : tz_info;
}
Sourceval make : ?tz:Time_zone.t -> ?ns:int -> ?frac:float -> year:int -> month:month -> day:int -> hour:int -> minute:int -> second:int -> unit -> t option

Constructs a date time providing only a time zone (defaults to local time zone).

Nanosecond used is the addition of ns and frac * number of nanoseconds in one second.

A precise offset is inferred if possible.

Note that this may yield a ambiguous date time if the time zone has varying offsets, e.g. DST.

See make_precise for the most precise construction.

Sourceval make_exn : ?tz:Time_zone.t -> ?ns:int -> ?frac:float -> year:int -> month:month -> day:int -> hour:int -> minute:int -> second:int -> unit -> t
Sourceval make_precise : ?tz:Time_zone.t -> ?ns:int -> ?frac:float -> year:int -> month:month -> day:int -> hour:int -> minute:int -> second:int -> tz_offset_s:tz_offset_s -> unit -> t option

Constructs a date time providing time zone offset in seconds, and optionally a time zone.

Nanosecond used is the addition of ns and frac * number of nanoseconds in one second.

If a time zone is provided, then the offset is checked against the time zone record to make sure the time zone does use said offset for the particular date time.

Sourceval make_precise_exn : ?tz:Time_zone.t -> ?ns:int -> ?frac:float -> year:int -> month:month -> day:int -> hour:int -> minute:int -> second:int -> tz_offset_s:tz_offset_s -> unit -> t
Sourcetype 'a local_result = [
  1. | `Single of 'a
  2. | `Ambiguous of 'a * 'a
]

Result for when a local date time may be involved, e.g. using a date time with no precise time zone offset attached.

  • `Single is yielded when the date time maps to exactly one 'a. This happens when date time carries an accurate offset, or when the date time is not affected by any offset shifts (thus an accurate offset can be inferred).
  • `Ambiguous is yielded when date time maps to more than one (exactly two) 'a. This happens when DST ends and "goes back an hour" for instance.
Sourceval to_timestamp : t -> timestamp local_result
Sourceval to_timestamp_single : t -> timestamp
Sourceval to_timestamp_float : t -> float local_result
Sourceval to_timestamp_float_single : t -> float
Sourceval min_of_local_result : 'a local_result -> 'a
Sourceval max_of_local_result : 'a local_result -> 'a
Sourceval of_timestamp : ?tz_of_date_time:Time_zone.t -> timestamp -> t option
Sourceval of_timestamp_float : ?tz_of_date_time:Time_zone.t -> float -> t option
Sourceval equal : t -> t -> bool
Sourceval min : t
Sourceval max : t
Sourceval now : ?tz_of_date_time:Time_zone.t -> unit -> t
Sourceval to_weekday : t -> weekday
Sourceexception Date_time_cannot_deduce_tz_offset_s of t
Sourceval pp : ?format:string -> unit -> Format.formatter -> t -> unit

Pretty printing for date time.

Default format string:

{year} {mon:Xxx} {mday:0X} {hour:0X}:{min:0X}:{sec:0X} \
{tzoff-sign}{tzoff-hour:0X}:{tzoff-min:0X}:{tzoff-sec:0X}

Format string specification:

{{               literal {
{year}           year
{mon:Xxx}        abbreviated month name (e.g. Jan), casing of 'x' controls the casing
{mon:Xx*}        full month name (e.g. January), casing of first 'x' controls casing of first letter,
                 casing of second 'x' controls casing of following letters
{mon:cX}         month in number form (e.g. 01) character 'c' before 'X' is used for padding
                 (leave out character for no padding)
{mday:cX}        month day (e.g.  1) character 'c' before 'X' is used for padding
                 (leave out character for no padding)
{wday:Xxx}       abbreviated weekday name (e.g. Sun), the casing of 'x' controls the casing
{wday:Xx*}       full weekday name (e.g. Sunday), casing of first 'x' controls casing of first letter,
                 casing of second 'x' controls casing of following letters
{hour:cX}        hour in 24-hour format, character 'c' before 'X' determines padding
                 (leave out character for no padding)
{12hour:cX}      hour in 12-hour format, character 'c' before 'X' determines padding
                 (leave out character for no padding)
{min:cX}         minute, character 'c' before 'X' determines padding
                 (leave out character for no padding)
{sec:cX}         second, character 'c' before 'X' determines padding
                 (leave out character for no padding)
{ns}             nanosecond
{sec-frac:N}     fraction of second (only digits)
                 N determines the number of digits to take after decimal point
                 result is rounded to closest fraction of said precision
{tzoff-sign}     time zone offset sign ('+' or '-')
                 raises Date_time_cannot_deduce_tz_offset_s if time zone offset cannot be calculated
{tzoff-hour:cX}  time zone offset hour, follows same padding rule as "{hour:cX}"
                 raises Date_time_cannot_deduce_tz_offset_s if time zone offset cannot be calculated
{tzoff-min:cX}   time zone offset minute, follows same padding rule as "{min:cX}"
                 raises Date_time_cannot_deduce_tz_offset_s if time zone offset cannot be calculated
{tzoff-sec:cX}   time zone offset second, follows same padding rule as "{sec:cX}"
                 raises Date_time_cannot_deduce_tz_offset_s if time zone offset cannot be calculated
Sourceval to_string : ?format:string -> t -> string option

String conversion using pp.

Returns None instead of raising exception when time zone offset cannot be deduced but required by the format string

Sourceval pp_rfc3339 : ?precision:int -> unit -> Format.formatter -> t -> unit
Sourceval pp_rfc3339_milli : Format.formatter -> t -> unit
Sourceval pp_rfc3339_micro : Format.formatter -> t -> unit
Sourceval pp_rfc3339_nano : Format.formatter -> t -> unit
Sourceval to_rfc3339 : ?precision:int -> t -> string option

Returns None if time zone offset cannot be deduced

Sourceval to_rfc3339_milli : t -> string option
Sourceval to_rfc3339_micro : t -> string option
Sourceval to_rfc3339_nano : t -> string option
Sourceval of_iso8601 : string -> (t, string) result
Sourceval to_sexp : t -> CCSexp.t
Sourceval to_sexp_string : t -> string
Sourceval of_sexp : CCSexp.t -> (t, string) result
Sourceval of_sexp_string : string -> (t, string) result
Sourceval pp_sexp : Format.formatter -> t -> unit