Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file time_ns_intf.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533open!Importopen!Import_timemoduletypeOption=sigincludeImmediate_option.S_int63includeIdentifiablewithtypet:=tendmoduletypeSpan=sigtypet=Core_kernel.Time_ns.Span.t[@@derivingtyperep,sexp_of]includeIdentifiablewithtypet:=tincludeComparable.With_zerowithtypet:=tvalarg_type:tCore_kernel.Command.Arg_type.t(** Similar to {!Time.Span.Parts}. *)moduleParts:sigtypet=private{sign:Sign.t;hr:int;min:int;sec:int;ms:int;us:int;ns:int}[@@derivingsexp]endvalnanosecond:tvalmicrosecond:tvalmillisecond:tvalsecond:tvalminute:tvalhour:tvalday:tvalof_ns:float->tvalof_us:float->tvalof_ms:float->tvalof_sec:float->tvalof_min:float->tvalof_hr:float->tvalof_day:float->tvalto_ns:t->floatvalto_us:t->floatvalto_ms:t->floatvalto_sec:t->floatvalto_min:t->floatvalto_hr:t->floatvalto_day:t->floatvalof_int_us:int->tvalof_int_ms:int->tvalof_int_sec:int->tvalto_int_us:t->intvalto_int_ms:t->intvalto_int_sec:t->intvalzero:tvalmin_value:tvalmax_value:tval(+):t->t->t(** overflows silently *)val(-):t->t->t(** overflows silently *)valabs:t->tvalneg:t->tvalscale:t->float->tvalscale_int:t->int->t(** overflows silently *)valdiv:t->t->Int63.tval(/):t->float->tval(//):t->t->float(** Overflows silently. *)valcreate:?sign:Sign.t->?day:int->?hr:int->?min:int->?sec:int->?ms:int->?us:int->?ns:int->unit->tvalto_short_string:t->stringvalrandomize:t->percent:Percent.t->tvalto_parts:t->Parts.tvalto_unit_of_time:t->Unit_of_time.tvalof_unit_of_time:Unit_of_time.t->t(** See [Time.Span.to_string_hum]. *)valto_string_hum:?delimiter:char(** defaults to ['_'] *)->?decimals:int(** defaults to 3 *)->?align_decimal:bool(** defaults to [false] *)->?unit_of_time:Unit_of_time.t(** defaults to [to_unit_of_time t] *)->t->string(** See [Core_kernel.Time_ns.Span]. *)valto_span:t->Time.Span.t[@@deprecated"[since 2019-01] use [to_span_float_round_nearest] or \
[to_span_float_round_nearest_microsecond]"]valof_span:Time.Span.t->t[@@deprecated"[since 2019-01] use [of_span_float_round_nearest] or \
[of_span_float_round_nearest_microsecond]"]valto_span_float_round_nearest:t->Time.Span.tvalto_span_float_round_nearest_microsecond:t->Time.Span.tvalof_span_float_round_nearest:Time.Span.t->tvalof_span_float_round_nearest_microsecond:Time.Span.t->tincludeRobustly_comparablewithtypet:=tvalto_int63_ns:t->Int63.t(** Fast, implemented as the identity function. *)valof_int63_ns:Int63.t->t(** Somewhat fast, implemented as a range check. *)(** Will raise on 32-bit platforms with spans corresponding to contemporary {!now}.
Consider [to_int63_ns] instead. *)valto_int_ns:t->intvalof_int_ns:int->t(** The only condition [to_proportional_float] is supposed to satisfy is that for all
[t1, t2 : t]: [to_proportional_float t1 /. to_proportional_float t2 = t1 // t2]. *)valto_proportional_float:t->floatmoduleStable:sigmoduleV1:sigtypenonrect=t[@@derivinghash]includeStable_int63ablewithtypet:=tendmoduleV2:sigtypenonrect=t[@@derivinghash]includeStable_int63ablewithtypet:=tendendvalrandom:?state:Random.State.t->unit->t(** [Span.Option.t] is like [Span.t option], except that the value is immediate on
architectures where [Int63.t] is immediate. This module should mainly be used to
avoid allocations. *)moduleOption:sigincludeOptionwithtypevalue:=tmoduleStable:sigmoduleV1:Stable_int63ablewithtypet=tmoduleV2:Stable_int63ablewithtypet=tendendendmoduletypeOfday=sigincludemoduletypeofstructincludeTime_ns.Ofdayendvalarg_type:tCore_kernel.Command.Arg_type.tvalnow:zone:Time.Zone.t->tvalto_ofday:t->Time.Ofday.t[@@deprecated"[since 2019-01] use [to_ofday_float_round_nearest] or \
[to_ofday_float_round_nearest_microsecond]"]valof_ofday:Time.Ofday.t->t[@@deprecated"[since 2019-01] use [of_ofday_float_round_nearest] or \
[of_ofday_float_round_nearest_microsecond]"]valto_ofday_float_round_nearest:t->Time.Ofday.tvalto_ofday_float_round_nearest_microsecond:t->Time.Ofday.tvalof_ofday_float_round_nearest:Time.Ofday.t->tvalof_ofday_float_round_nearest_microsecond:Time.Ofday.t->tmoduleZoned:sig(** Sexps look like "(12:01 nyc)"
Two [t]'s may or may not correspond to the same times depending on which date
they're evaluated. *)typet[@@derivingbin_io,sexp,hash]includePretty_printer.Swithtypet:=tincludeStringablewithtypet:=t(** Strings look like "12:01 nyc" *)valarg_type:tCore_kernel.Command.Arg_type.tvalcreate:Time_ns.Ofday.t->Time.Zone.t->tvalcreate_local:Time_ns.Ofday.t->tvalofday:t->Time_ns.Ofday.tvalzone:t->Time.Zone.tvalto_time_ns:t->Date.t->Time_ns.tmoduleWith_nonchronological_compare:sig(** It is possible to consistently compare [t]'s, but due to the complexities of
time zones and daylight savings, the resulting ordering is not chronological.
That is, [compare t1 t2 > 0] does not imply [t2] occurs after [t1] every day,
or any day. *)typenonrect=t[@@derivingbin_io,sexp,compare,hash]endendmoduleOption:sigincludeOptionwithtypevalue:=tmoduleStable:sigmoduleV1:Stable_int63ablewithtypet=tendendend(** An absolute point in time, more efficient and precise than the [float]-based {!Time},
but representing a narrower range of times.
This module represents absolute times with nanosecond precision, approximately between
the years 1823 and 2116 CE.
You should normally default to using [Time] instead of this module! The reasons are:
- Many functions around our libraries expect [Time.t] values, so it will likely be
much more convenient for you.
- It leads to greater consistency across different codebases. It would be bad to end
up with half our libraries expecting [Time.t] and the other half expecting
[Time_ns.t].
- [Time_ns] silently ignores overflow.
Some reasons you might want want to actually prefer [Time_ns.t] in certain cases:
- It has superior performance.
- It uses [int]s rather than [float]s internally, which makes certain things easier to
reason about, since [int]s respect a bunch of arithmetic identities that [float]s
don't, e.g., [x + (y + z) = (x + y) + z].
Neither [Core.Time_ns] nor [Core.Time] are available in Javascript.
All in all, it would have been nice to have chosen [Time_ns.t] to begin with, but
we're unlikely to flip everything to [Time_ns.t] in the short term (see comment at the
end of [time_ns.ml]).
See {!Core_kernel.Time_ns} for additional low level documentation. *)moduletypeTime_ns=sigtypet=Core_kernel.Time_ns.t[@@derivingtyperep]moduleSpan:Spanvalarg_type:tCore_kernel.Command.Arg_type.t(** [Option.t] is like [t option], except that the value is immediate. This module
should mainly be used to avoid allocations. *)moduleOption:sigincludeOptionwithtypevalue:=tmoduleStable:sigmoduleV1:Stable_int63ablewithtypet=tendend(** See {!Time.Ofday}. *)moduleOfday:Ofday(** String conversions use the local timezone by default. Sexp conversions use
[get_sexp_zone ()] by default, which can be overridden by calling [set_sexp_zone].
These default time zones are used when writing a time, and when reading a time with
no explicit zone or UTC offset.
Sexps and strings display the date, ofday, and UTC offset of [t] relative to the
appropriate time zone. *)includeIdentifiablewithtypet:=tmoduleZone:moduletypeofTime.Zonewithtypet=Time.Zone.t(** These functions are identical to those in [Time] and get/set the same variable. *)valget_sexp_zone:unit->Zone.tvalset_sexp_zone:Zone.t->unit(** [t_of_sexp_abs sexp] as [t_of_sexp], but demands that [sexp] indicate the timezone
the time is expressed in. *)valt_of_sexp_abs:Sexp.t->tvalsexp_of_t_abs:t->zone:Zone.t->Sexp.tvalepoch:t(** Unix epoch (1970-01-01 00:00:00 UTC) *)valmin_value:tvalmax_value:tvalnow:unit->tvaladd:t->Span.t->t(** overflows silently *)valsub:t->Span.t->t(** overflows silently *)valnext:t->t(** overflows silently *)valprev:t->t(** overflows silently *)valdiff:t->t->Span.t(** overflows silently *)valabs_diff:t->t->Span.t(** overflows silently *)valto_span_since_epoch:t->Span.tvalof_span_since_epoch:Span.t->tvalto_time:t->Time.t[@@deprecated"[since 2019-01] use [to_time_float_round_nearest] or \
[to_time_float_round_nearest_microsecond]"]valof_time:Time.t->t[@@deprecated"[since 2019-01] use [of_time_float_round_nearest] or \
[of_time_float_round_nearest_microsecond]"]valto_time_float_round_nearest:t->Time.tvalto_time_float_round_nearest_microsecond:t->Time.tvalof_time_float_round_nearest:Time.t->tvalof_time_float_round_nearest_microsecond:Time.t->tvalto_string_fix_proto:[`Utc|`Local]->t->stringvalof_string_fix_proto:[`Utc|`Local]->string->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(** This is like [of_string] except that if the string doesn't specify the zone then it
raises rather than assume the local timezone. *)valof_string_abs:string->t(** 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 *)valto_sec_string: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_ns.t *)valof_localized_string:zone:Zone.t->string->t(** [of_string_gen ~if_no_timezone s] attempts to parse [s] to a [t]. If [s] doesn't
supply a time zone [if_no_timezone] is consulted. *)valof_string_gen:if_no_timezone:[`Fail|`Local|`Use_this_oneofZone.t]->string->t(** [to_string_iso8601_basic] returns 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.000000000Z" ]
*)valto_string_iso8601_basic:t->zone:Zone.t->stringvalto_int63_ns_since_epoch:t->Int63.tvalof_int63_ns_since_epoch:Int63.t->t(** Will raise on 32-bit platforms. Consider [to_int63_ns_since_epoch] instead. *)valto_int_ns_since_epoch:t->intvalof_int_ns_since_epoch:int->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_ns. *)valof_filename_string:string->zone:Zone.t->t(** See [Core_kernel.Time_ns].
Overflows silently. *)valnext_multiple:?can_equal_after:bool(** default is [false] *)->base:t->after:t->interval:Span.t->unit->t(** See [Core_kernel.Time_ns].
Overflows silently. *)valprev_multiple:?can_equal_before:bool(** default is [false] *)->base:t->before:t->interval:Span.t->unit->tvalof_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_ofday:t->zone:Zone.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_date_ofday:t->zone:Zone.t->Date.t*Ofday.tvaloccurrence:[`First_after_or_at|`Last_before_or_at]->t->ofday:Ofday.t->zone:Time.Zone.t->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(** 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.t)valutc_offset:t->zone:Zone.t->Span.t(** [pause span] sleeps for [span] time. *)valpause:Span.t->unit(** [interruptible_pause span] sleeps for [span] time unless interrupted (e.g. by
delivery of a signal), in which case the remaining unslept portion of time is
returned. *)valinterruptible_pause:Span.t->[`Ok|`RemainingofSpan.t](** [pause_forever] sleeps indefinitely. *)valpause_forever:unit->never_returnsmoduleStable:sigmoduleV1:Stable_int63ablewithtypet=tmoduleOption:sigmoduleV1:Stable_int63ablewithtypet=Option.tendmoduleSpan:sigmoduleV1:sigtypet=Span.t[@@derivinghash]includeStable_int63ablewithtypet:=tendmoduleV2:sigtypet=Span.t[@@derivinghash]includeStable_int63ablewithtypet:=tendmoduleOption:sigmoduleV1:Stable_int63ablewithtypet=Span.Option.tmoduleV2:Stable_int63ablewithtypet=Span.Option.tendendmoduleOfday:sigmoduleV1:Stable_int63ablewithtypet=Ofday.tmoduleZoned:sigmoduleV1:sigtypenonrect=Ofday.Zoned.t[@@derivinghash]includeStable_without_comparatorwithtypet:=tendendmoduleOption:sigmoduleV1:Stable_int63ablewithtypet=Ofday.Option.tendendendvalrandom:?state:Random.State.t->unit->tend