123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246open!Importopen!Std_internalmoduleDate=Date0moduletypeZone=sigmoduleTime:Time0_intf.SincludeZone.Swithtypet=Zone.tandmoduleTime_in_seconds:=Time(** [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. *)valabbreviation:t->Time.t->string(** [absolute_time_of_date_and_ofday] and [date_and_ofday_of_absolute_time] convert
between absolute times and date + ofday forms. These are low level functions not
intended for most clients. These functions read and write the zone's cached index.
*)valabsolute_time_of_date_and_ofday:t->Time.Date_and_ofday.t->Time.tvaldate_and_ofday_of_absolute_time:t->Time.t->Time.Date_and_ofday.t(** 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. *)valnext_clock_shift:t->strictly_after:Time.t->(Time.t*Time.Span.t)option(** As [next_clock_shift], but *at or before* the given time. *)valprev_clock_shift:t->at_or_before:Time.t->(Time.t*Time.Span.t)optionendmoduletypeBasic=sigmoduleTime:Time0_intf.S(*_ necessary to preserve type equality with the Time functor argument *)includemoduletypeofstructincludeTimeend[@ocaml.remove_aliases](** [now ()] returns a [t] representing the current time *)valnow:unit->tmoduleZone:ZonewithmoduleTime:=Time(** {6 Basic operations on times} *)(** [add t s] adds the span [s] to time [t] and returns the resulting time.
NOTE: adding spans as a means of adding days is not accurate, and may run into trouble
due to shifts in daylight savings time, float arithmetic issues, and leap seconds.
See the comment at the top of Zone.mli for a more complete discussion of some of
the issues of time-keeping. For spans that cross date boundaries, use date functions
instead.
*)valadd:t->Span.t->t(** [sub t s] subtracts the span [s] from time [t] and returns the
resulting time. See important note for [add]. *)valsub:t->Span.t->t(** [diff t1 t2] returns time [t1] minus time [t2]. *)valdiff:t->t->Span.t(** [abs_diff t1 t2] returns the absolute span of time [t1] minus time [t2]. *)valabs_diff:t->t->Span.tendmoduletypeShared=sigtypetincludeQuickcheck.S_rangewithtypet:=tmoduleSpan:sigtypetendmoduleOfday:sigtypetend(** {6 Comparisons} *)valis_earlier:t->than:t->boolvalis_later:t->than:t->bool(** {6 Conversions} *)valof_date_ofday:zone:Zone.t->Date.t->Ofday.t->t(** Because timezone offsets change throughout the year (clocks go forward or back) some
local times can occur twice or not at all. In the case that they occur twice, this
function gives [`Twice] with both occurrences in order; if they do not occur at all,
this function gives [`Never] with the time at which the local clock skips over the
desired time of day.
Note that this is really only intended to work with DST transitions and not unusual or
dramatic changes, like the calendar change in 1752 (run "cal 9 1752" in a shell to
see). In particular it makes the assumption that midnight of each day is unambiguous.
Most callers should use {!of_date_ofday} rather than this function. In the [`Twice]
and [`Never] cases, {!of_date_ofday} will return reasonable times for most uses. *)valof_date_ofday_precise:Date.t->Ofday.t->zone:Zone.t->[`Onceoft|`Twiceoft*t|`Neveroft]valto_date_ofday:t->zone:Zone.t->Date.t*Ofday.t(** Always returns the [Date.t * Ofday.t] that [to_date_ofday] would have returned, and in
addition returns a variant indicating whether the time is associated with a time zone
transition.
{v
- `Only -> there is a one-to-one mapping between [t]'s and
[Date.t * Ofday.t] pairs
- `Also_at -> there is another [t] that maps to the same [Date.t * Ofday.t]
(this date/time pair happened twice because the clock fell back)
- `Also_skipped -> there is another [Date.t * Ofday.t] pair that never happened (due
to a jump forward) that [of_date_ofday] would map to the same
[t].
v}
*)valto_date_ofday_precise:t->zone:Zone.t->Date.t*Ofday.t*[`Only|`Also_atoft|`Also_skippedofDate.t*Ofday.t]valto_date:t->zone:Zone.t->Date.tvalto_ofday:t->zone:Zone.t->Ofday.t(** For performance testing only; [reset_date_cache ()] resets an internal cache used to
speed up [to_date] and related functions when called repeatedly on times that fall
within the same day. *)valreset_date_cache:unit->unit(** Unlike [Time_ns], this module purposely omits [max_value] and [min_value]:
1. They produce unintuitive corner cases because most people's mental models of time
do not include +/- infinity as concrete values
2. In practice, when people ask for these values, it is for questionable uses, e.g.,
as null values to use in place of explicit options. *)(** midnight, Jan 1, 1970 in UTC *)valepoch:t(** It's unspecified what happens if the given date/ofday/zone correspond to more than
one date/ofday pair in the other zone. *)valconvert:from_tz:Zone.t->to_tz:Zone.t->Date.t->Ofday.t->Date.t*Ofday.tvalutc_offset:t->zone:Zone.t->Span.t(** {6 Other string conversions} *)(** The [{to,of}_string] functions in [Time] convert to UTC time, because a local time
zone is not necessarily available. They are generous in what they will read in. *)includeStringablewithtypet:=t(** [to_filename_string t ~zone] converts [t] to string with format
YYYY-MM-DD_HH-MM-SS.mmm which is suitable for using in filenames. *)valto_filename_string:t->zone:Zone.t->string(** [of_filename_string s ~zone] converts [s] that has format YYYY-MM-DD_HH-MM-SS.mmm into
time. *)valof_filename_string:string->zone:Zone.t->t(** [to_string_abs ~zone t] is the same as [to_string t] except that it uses the given
time zone. *)valto_string_abs:t->zone:Zone.t->string(** [to_string_abs_trimmed] is the same as [to_string_abs], but drops trailing seconds
and milliseconds if they are 0. *)valto_string_abs_trimmed:t->zone:Zone.t->stringvalto_string_abs_parts:t->zone:Zone.t->stringlist(** Same as [to_string_abs_trimmed], except it leaves off the timezone, so won't
reliably round trip. *)valto_string_trimmed:t->zone:Zone.t->string(** Same as [to_string_abs], but without milliseconds and the timezone. May raise if
[zone] offsets move the apparent value beyond [min_value_representable] and
[max_value_representable]. *)valto_sec_string:t->zone:Zone.t->string(** Same as [to_sec_string] but includes timezone *)valto_sec_string_with_zone:t->zone:Zone.t->string(** [of_localized_string ~zone str] read in the given string assuming that it represents
a time in zone and return the appropriate Time.t *)valof_localized_string:zone:Zone.t->string->t(** [of_string_gen ~default_zone ~find_zone s] attempts to parse [s] as a [t], calling
out to [default_zone] and [find_zone] as needed. *)valof_string_gen:default_zone:(unit->Zone.t)->find_zone:(string->Zone.t)->string->t(** [to_string_iso8601_basic] return a string representation of the following form:
%Y-%m-%dT%H:%M:%S.%s%Z
e.g.
[ to_string_iso8601_basic ~zone:Time.Zone.utc epoch = "1970-01-01T00:00:00.000000Z" ]
*)valto_string_iso8601_basic:t->zone:Zone.t->string(** [occurrence side time ~ofday ~zone] returns a [Time.t] that is the occurrence of
ofday (in the given [zone]) that is the latest occurrence (<=) [time] or the
earliest occurrence (>=) [time], according to [side].
NOTE: If the given time converted to wall clock time in the given zone is equal to
ofday then the t returned will be equal to the t given.
*)valoccurrence:[`First_after_or_at|`Last_before_or_at]->t->ofday:Ofday.t->zone:Zone.t->tendmoduletypeS=sigincludeBasicincludeSharedwithtypet:=twithmoduleSpan:=SpanwithmoduleOfday:=Ofdayvalof_string:string->t[@@deprecated"[since 2021-04] Use [of_string_with_utc_offset] or [Time_float_unix.of_string]"](** [of_string_with_utc_offset] requires its input to have an explicit
UTC offset, e.g. [2000-01-01 12:34:56.789012-23], or use the UTC zone, "Z",
e.g. [2000-01-01 12:34:56.789012Z]. *)valof_string_with_utc_offset:string->tvalto_string:t->string[@@deprecated"[since 2021-04] Use [to_string_utc] or [Time_float_unix.to_string]"](** [to_string_utc] generates a time string with the UTC zone, "Z", e.g. [2000-01-01
12:34:56.789012Z]. *)valto_string_utc:t->stringendmoduletypeTime=sigmoduletypeS=SmoduleMake(Time:Time0_intf.S):SwithmoduleTime:=Timeend