144 lines
No EOL
16 KiB
HTML
144 lines
No EOL
16 KiB
HTML
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>time | Documentation</title><meta name="description" content="Documentation for Documentation"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/search.js" id="tsd-search-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"</script><header class="tsd-page-toolbar">
|
|
<div class="tsd-toolbar-contents container">
|
|
<div class="table-cell" id="tsd-search" data-base="..">
|
|
<div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M15.7824 13.833L12.6666 10.7177C12.5259 10.5771 12.3353 10.499 12.1353 10.499H11.6259C12.4884 9.39596 13.001 8.00859 13.001 6.49937C13.001 2.90909 10.0914 0 6.50048 0C2.90959 0 0 2.90909 0 6.49937C0 10.0896 2.90959 12.9987 6.50048 12.9987C8.00996 12.9987 9.39756 12.4863 10.5008 11.6239V12.1332C10.5008 12.3332 10.5789 12.5238 10.7195 12.6644L13.8354 15.7797C14.1292 16.0734 14.6042 16.0734 14.8948 15.7797L15.7793 14.8954C16.0731 14.6017 16.0731 14.1267 15.7824 13.833ZM6.50048 10.499C4.29094 10.499 2.50018 8.71165 2.50018 6.49937C2.50018 4.29021 4.28781 2.49976 6.50048 2.49976C8.71001 2.49976 10.5008 4.28708 10.5008 6.49937C10.5008 8.70852 8.71314 10.499 6.50048 10.499Z" fill="var(--color-text)"></path></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div>
|
|
<div class="field">
|
|
<div id="tsd-toolbar-links"></div></div>
|
|
<ul class="results">
|
|
<li class="state loading">Preparing search index...</li>
|
|
<li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">Documentation</a></div>
|
|
<div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><rect x="1" y="3" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="7" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="11" width="14" height="2" fill="var(--color-text)"></rect></svg></a></div></div></header>
|
|
<div class="container container-main">
|
|
<div class="col-content">
|
|
<div class="tsd-page-title">
|
|
<ul class="tsd-breadcrumb">
|
|
<li><a href="../modules.html">Documentation</a></li>
|
|
<li><a href="time.html">time</a></li></ul>
|
|
<h1>Namespace time</h1></div>
|
|
<section class="tsd-panel tsd-comment">
|
|
<div class="tsd-comment tsd-typography"><p>Package time provides functionality for measuring and displaying time.</p>
|
|
<p>The calendrical calculations always assume a Gregorian calendar, with
|
|
no leap seconds.</p>
|
|
<a id="md:monotonic-clocks" class="tsd-anchor"></a><h1><a href="#md:monotonic-clocks">Monotonic Clocks</a></h1><p>Operating systems provide both a “wall clock,” which is subject to
|
|
changes for clock synchronization, and a “monotonic clock,” which is
|
|
not. The general rule is that the wall clock is for telling time and
|
|
the monotonic clock is for measuring time. Rather than split the API,
|
|
in this package the Time returned by [time.Now] contains both a wall
|
|
clock reading and a monotonic clock reading; later time-telling
|
|
operations use the wall clock reading, but later time-measuring
|
|
operations, specifically comparisons and subtractions, use the
|
|
monotonic clock reading.</p>
|
|
<p>For example, this code always computes a positive elapsed time of
|
|
approximately 20 milliseconds, even if the wall clock is changed during
|
|
the operation being timed:</p>
|
|
<pre><code><span class="hl-1"> </span><span class="hl-8">start</span><span class="hl-1"> := </span><span class="hl-4">time</span><span class="hl-1">.</span><span class="hl-3">Now</span><span class="hl-1">()</span><br/><span class="hl-1"> ... </span><span class="hl-4">operation</span><span class="hl-1"> </span><span class="hl-4">that</span><span class="hl-1"> </span><span class="hl-4">takes</span><span class="hl-1"> </span><span class="hl-7">20</span><span class="hl-1"> </span><span class="hl-4">milliseconds</span><span class="hl-1"> ...</span><br/><span class="hl-1"> </span><span class="hl-8">t</span><span class="hl-1"> := </span><span class="hl-4">time</span><span class="hl-1">.</span><span class="hl-3">Now</span><span class="hl-1">()</span><br/><span class="hl-1"> </span><span class="hl-8">elapsed</span><span class="hl-1"> := </span><span class="hl-4">t</span><span class="hl-1">.</span><span class="hl-3">Sub</span><span class="hl-1">(</span><span class="hl-4">start</span><span class="hl-1">)</span>
|
|
</code><button>Copy</button></pre>
|
|
<p>Other idioms, such as <a href="start">time.Since</a>, <a href="deadline">time.Until</a>, and
|
|
time.Now().Before(deadline), are similarly robust against wall clock
|
|
resets.</p>
|
|
<p>The rest of this section gives the precise details of how operations
|
|
use monotonic clocks, but understanding those details is not required
|
|
to use this package.</p>
|
|
<p>The Time returned by time.Now contains a monotonic clock reading.
|
|
If Time t has a monotonic clock reading, t.Add adds the same duration to
|
|
both the wall clock and monotonic clock readings to compute the result.
|
|
Because t.AddDate(y, m, d), t.Round(d), and t.Truncate(d) are wall time
|
|
computations, they always strip any monotonic clock reading from their results.
|
|
Because t.In, t.Local, and t.UTC are used for their effect on the interpretation
|
|
of the wall time, they also strip any monotonic clock reading from their results.
|
|
The canonical way to strip a monotonic clock reading is to use t = t.Round(0).</p>
|
|
<p>If Times t and u both contain monotonic clock readings, the operations
|
|
t.After(u), t.Before(u), t.Equal(u), t.Compare(u), and t.Sub(u) are carried out
|
|
using the monotonic clock readings alone, ignoring the wall clock
|
|
readings. If either t or u contains no monotonic clock reading, these
|
|
operations fall back to using the wall clock readings.</p>
|
|
<p>On some systems the monotonic clock will stop if the computer goes to sleep.
|
|
On such a system, t.Sub(u) may not accurately reflect the actual
|
|
time that passed between t and u. The same applies to other functions and
|
|
methods that subtract times, such as [Since], [Until], [Before], [After],
|
|
[Add], [Sub], [Equal] and [Compare]. In some cases, you may need to strip
|
|
the monotonic clock to get accurate results.</p>
|
|
<p>Because the monotonic clock reading has no meaning outside
|
|
the current process, the serialized forms generated by t.GobEncode,
|
|
t.MarshalBinary, t.MarshalJSON, and t.MarshalText omit the monotonic
|
|
clock reading, and t.Format provides no format for it. Similarly, the
|
|
constructors [time.Date], [time.Parse], [time.ParseInLocation], and [time.Unix],
|
|
as well as the unmarshalers t.GobDecode, t.UnmarshalBinary.
|
|
t.UnmarshalJSON, and t.UnmarshalText always create times with
|
|
no monotonic clock reading.</p>
|
|
<p>The monotonic clock reading exists only in [Time] values. It is not
|
|
a part of [Duration] values or the Unix times returned by t.Unix and
|
|
friends.</p>
|
|
<p>Note that the Go == operator compares not just the time instant but
|
|
also the [Location] and the monotonic clock reading. See the
|
|
documentation for the Time type for a discussion of equality
|
|
testing for Time values.</p>
|
|
<p>For debugging, the result of t.String does include the monotonic
|
|
clock reading if present. If t != u because of different monotonic clock readings,
|
|
that difference will be visible when printing t.String() and u.String().</p>
|
|
<a id="md:timer-resolution" class="tsd-anchor"></a><h1><a href="#md:timer-resolution">Timer Resolution</a></h1><p>[Timer] resolution varies depending on the Go runtime, the operating system
|
|
and the underlying hardware.
|
|
On Unix, the resolution is ~1ms.
|
|
On Windows version 1803 and newer, the resolution is ~0.5ms.
|
|
On older Windows versions, the default resolution is ~16ms, but
|
|
a higher resolution may be requested using [golang.org/x/sys/windows.TimeBeginPeriod].</p>
|
|
</div>
|
|
<div class="tsd-comment tsd-typography"></div></section><aside class="tsd-sources">
|
|
<ul>
|
|
<li>Defined in <a href="https://github.com/pocketbase/tygoja/blob/1791847/test/types.d.ts#L306">types.d.ts:306</a></li>
|
|
<li>Defined in <a href="https://github.com/pocketbase/tygoja/blob/1791847/test/types.d.ts#L821">types.d.ts:821</a></li></ul></aside>
|
|
<section class="tsd-panel-group tsd-index-group">
|
|
<section class="tsd-panel tsd-index-panel">
|
|
<h3 class="tsd-index-heading uppercase">Index</h3>
|
|
<section class="tsd-index-section">
|
|
<h3 class="tsd-index-heading">Interfaces</h3>
|
|
<div class="tsd-index-list"><a href="../interfaces/time.Duration.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-256"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-interface)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.51 16V15.016H11.298V8.224H9.51V7.24H14.19V8.224H12.402V15.016H14.19V16H9.51Z" fill="var(--color-text)"></path></g></svg><span>Duration</span></a>
|
|
<a href="../interfaces/time.Location.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>Location</span></a>
|
|
<a href="../interfaces/time.Month.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>Month</span></a>
|
|
<a href="../interfaces/time.Time.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>Time</span></a>
|
|
<a href="../interfaces/time.Weekday.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>Weekday</span></a>
|
|
</div></section></section></section></div>
|
|
<div class="col-sidebar">
|
|
<div class="page-menu">
|
|
<div class="tsd-navigation settings">
|
|
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
|
|
<h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M4.93896 8.531L12 15.591L19.061 8.531L16.939 6.409L12 11.349L7.06098 6.409L4.93896 8.531Z" fill="var(--color-text)" id="icon-chevronDown"></path></svg>Settings</h3></summary>
|
|
<div class="tsd-accordion-details">
|
|
<div class="tsd-filter-visibility">
|
|
<h4 class="uppercase">Member Visibility</h4><form>
|
|
<ul id="tsd-filter-options">
|
|
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li>
|
|
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li>
|
|
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li>
|
|
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div>
|
|
<div class="tsd-theme-toggle">
|
|
<h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div>
|
|
<details open class="tsd-index-accordion tsd-page-navigation"><summary class="tsd-accordion-summary">
|
|
<h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="#icon-chevronDown"></use></svg>On This Page</h3></summary>
|
|
<div class="tsd-accordion-details">
|
|
<ul>
|
|
<li>
|
|
<ul>
|
|
<li><a href="#md:monotonic-clocks"><span>Monotonic <wbr/>Clocks</span></a></li>
|
|
<li><a href="#md:timer-resolution"><span>Timer <wbr/>Resolution</span></a></li></ul></li></ul></div></details></div>
|
|
<div class="site-menu">
|
|
<nav class="tsd-navigation"><a href="../modules.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-4"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-namespace)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.33 16V7.24H10.77L13.446 14.74C13.43 14.54 13.41 14.296 13.386 14.008C13.37 13.712 13.354 13.404 13.338 13.084C13.33 12.756 13.326 12.448 13.326 12.16V7.24H14.37V16H12.93L10.266 8.5C10.282 8.692 10.298 8.936 10.314 9.232C10.33 9.52 10.342 9.828 10.35 10.156C10.366 10.476 10.374 10.784 10.374 11.08V16H9.33Z" fill="var(--color-text)"></path></g></svg><span>Documentation</span></a>
|
|
<ul class="tsd-small-nested-navigation">
|
|
<li><a href="a.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>a</span></a></li>
|
|
<li><a href="b.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>b</span></a></li>
|
|
<li><a href="c.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>c</span></a></li>
|
|
<li>
|
|
<details class="tsd-index-accordion" open data-key="time"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="#icon-chevronDown"></use></svg><a href="time.html" class="current"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>time</span></a></summary>
|
|
<div class="tsd-accordion-details">
|
|
<ul class="tsd-nested-navigation">
|
|
<li><a href="../interfaces/time.Duration.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>Duration</span></a></li>
|
|
<li><a href="../interfaces/time.Location.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>Location</span></a></li>
|
|
<li><a href="../interfaces/time.Month.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>Month</span></a></li>
|
|
<li><a href="../interfaces/time.Time.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>Time</span></a></li>
|
|
<li><a href="../interfaces/time.Weekday.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-256"></use></svg><span>Weekday</span></a></li></ul></div></details></li>
|
|
<li><a href="../types/_TygojaAny.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-4194304"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-type-alias)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M11.31 16V8.224H8.91V7.24H14.79V8.224H12.39V16H11.31Z" fill="var(--color-text)"></path></g></svg><span>_<wbr/>Tygoja<wbr/>Any</span></a></li>
|
|
<li><a href="../types/_TygojaDict.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4194304"></use></svg><span>_<wbr/>Tygoja<wbr/>Dict</span></a></li>
|
|
<li><a href="../functions/_app.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-64"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-function)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.39 16V7.24H14.55V8.224H10.446V11.128H14.238V12.112H10.47V16H9.39Z" fill="var(--color-text)"></path></g></svg><span>$app</span></a></li></ul></nav></div></div></div>
|
|
<div class="tsd-generator">
|
|
<p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div>
|
|
<div class="overlay"></div></body></html> |