ocaml-opentelemetry/ptime/Ptime_clock/index.html
2025-07-23 14:08:20 +00:00

2 lines
6.2 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Ptime_clock (ptime.Ptime_clock)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.1.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../../index.html">Index</a> &#x00BB; <a href="../index.html">ptime</a> &#x00BB; Ptime_clock</nav><header class="odoc-preamble"><h1>Module <code><span>Ptime_clock</span></code></h1><p>POSIX time clock.</p><p><code>Ptime_clock</code> provides access to a system POSIX time clock and to the system's current time zone offset.</p><p>This time does not increase monotically and is subject to system calendar time adjustments. Use <code>Mtime</code> if you need monotonic wall-clock time to measure time spans.</p><p>Consult important information about <a href="#err" title="err">error handling</a> and <a href="#platform_support" title="platform_support">platform support</a>.</p></header><div class="odoc-tocs"><nav class="odoc-toc odoc-local-toc"><ul><li><a href="#clock">POSIX clock</a></li><li><a href="#tz">System time zone offset</a></li><li><a href="#raw">POSIX clock raw interface</a></li><li><a href="#err">Error handling</a></li><li><a href="#platform_support">Platform support</a></li></ul></nav></div><div class="odoc-content"><h2 id="clock"><a href="#clock" class="anchor"></a>POSIX clock</h2><div class="odoc-spec"><div class="spec value anchored" id="val-now"><a href="#val-now" class="anchor"></a><code><span><span class="keyword">val</span> now : <span>unit <span class="arrow">&#45;&gt;</span></span> <a href="../Ptime/index.html#type-t">Ptime.t</a></span></code></div><div class="spec-doc"><p><code>now ()</code> is the current POSIX time, by definition always on the UTC timeline.</p><p>Raises <code>Sys_error</code>, see <a href="#err" title="err">error handling</a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-period"><a href="#val-period" class="anchor"></a><code><span><span class="keyword">val</span> period : <span>unit <span class="arrow">&#45;&gt;</span></span> <span><a href="../Ptime/index.html#type-span">Ptime.span</a> option</span></span></code></div><div class="spec-doc"><p><code>period ()</code> is a positive POSIX time span representing the clock's period (if available).</p></div></div><h2 id="tz"><a href="#tz" class="anchor"></a>System time zone offset</h2><div class="odoc-spec"><div class="spec value anchored" id="val-current_tz_offset_s"><a href="#val-current_tz_offset_s" class="anchor"></a><code><span><span class="keyword">val</span> current_tz_offset_s : <span>unit <span class="arrow">&#45;&gt;</span></span> <span><a href="../Ptime/index.html#type-tz_offset_s">Ptime.tz_offset_s</a> option</span></span></code></div><div class="spec-doc"><p><code>current_tz_offset_s ()</code> is the system's current local time zone offset to UTC in seconds, if known. This is the duration local time - UTC time in seconds.</p></div></div><h2 id="raw"><a href="#raw" class="anchor"></a>POSIX clock raw interface</h2><div class="odoc-spec"><div class="spec value anchored" id="val-now_d_ps"><a href="#val-now_d_ps" class="anchor"></a><code><span><span class="keyword">val</span> now_d_ps : <span>unit <span class="arrow">&#45;&gt;</span></span> int * int64</span></code></div><div class="spec-doc"><p><code>now_d_ps ()</code> is <code>(d, ps)</code> representing POSIX time occuring at <code>d</code> * 86'400e12 + <code>ps</code> POSIX picoseconds from the epoch 1970-01-01 00:00:00 UTC. <code>ps</code> is in the range [<code>0</code>;<code>86_399_999_999_999_999L</code>].</p><p>Raises <code>Sys_error</code>, see <a href="#err" title="err">error handling</a></p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-period_d_ps"><a href="#val-period_d_ps" class="anchor"></a><code><span><span class="keyword">val</span> period_d_ps : <span>unit <span class="arrow">&#45;&gt;</span></span> <span><span>(int * int64)</span> option</span></span></code></div><div class="spec-doc"><p><code>period_d_ps ()</code> is if available <code>Some (d, ps)</code> representing the clock's picosecond period <code>d</code> * 86'400e12 + <code>ps</code>. <code>ps</code> is in the range [<code>0</code>;<code>86_399_999_999_999_999L</code>].</p></div></div><h2 id="err"><a href="#err" class="anchor"></a>Error handling</h2><p>The functions <a href="#val-now"><code>now</code></a> and <a href="#val-now_d_ps"><code>now_d_ps</code></a> raise <code>Sys_error</code> whenever they can't determine the current time or that it doesn't fit in <code>Ptime</code>'s well-defined <a href="../Ptime/index.html#type-t" title="Ptime.t">range</a>. This exception should only be catched at the toplevel of your program to log it and abort the program. It indicates a serious error condition in the system.</p><p>All the other functions, whose functionality is less essential, simply silently return <code>None</code> if they can't determine the information either because it is unavailable or because an error occured.</p><h2 id="platform_support"><a href="#platform_support" class="anchor"></a>Platform support</h2><ul><li>Platforms with a POSIX clock (includes Linux) use <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html"><code>clock_gettime</code></a> with <code>CLOCK_REALTIME</code>.</li><li>On Darwin <a href="http://pubs.opengroup.org/onlinepubs/9699919799/"><code>gettimeofday</code></a> is used.</li><li>On Windows <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724390(v=vs.85).aspx"><code>GetSystemTime</code></a> and <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724421(v=vs.85).aspx"><code>GetTimeZoneInformation</code></a> are used.</li><li>On JavaScript <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-date.now"><code>Date.now ()</code></a> and <a href="http://www.ecma-international.org/ecma-262/6.0/index.html#sec-date.prototype.gettimezoneoffset"><code>Date.prototype.getTimezoneOffset</code></a> are used.</li></ul></div></body></html>