<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>book/src/date-and-time.md - fork/numbat @ master</title>
<meta name="description" content="book/src/date-and-time.md in fork/numbat at master.">
<meta property="og:title" content="book/src/date-and-time.md - fork/numbat @ master">
<meta property="og:description" content="book/src/date-and-time.md in fork/numbat at master.">
<meta property="og:type" content="website">
<meta property="og:site_name" content="git.julia.blue">
<link rel="stylesheet" href="/css/style.css?v=62">
<script type="module" src="/js/main.js?v=62"></script>
</head>
<body>
<main data-ref="master" data-tip="b070b880c8a713bac881084034ea6f0d857868ed">
<noscript>
  <div class="callout">
    <p>
      hey! this is a static git repo viewer. commit diffs, file history,
      older commits and other revisions won't load without javascript.
    </p>
    <p>
      you are still able to view source files on branch/tag tips,
      but the experience is degraded.
    </p>
  </div>
</noscript>
<header class="repo"><div>
<h1>fork/numbat</h1>
</div>
<pre class="clone">git clone https://git.julia.blue/fork/numbat</pre>
</header>
<p class="snapshot-commit"><span class="commit-author">David Peter</span><span class="commit-message" data-commit="a26bfed8db62a187ff7f01a6704a7a2168087496">Add 'time' function</span><span class="snapshot-sha sha" data-commit="a26bfed8db62a187ff7f01a6704a7a2168087496">a26bfed</span><time datetime="2024-02-12T22:07:36+01:00" title="2024-02-12 22:07:36 +0100">2024-02-12</time></p>
<header class="topbar"><details class="switcher"><summary>master</summary><div class="menu"><strong>branches</strong><a class="current" href="/fork/numbat/ref/master/">master</a><strong>tags</strong><a href="/fork/numbat/ref/v1.6.0/">v1.6.0</a><a href="/fork/numbat/ref/v1.6.1/">v1.6.1</a><a href="/fork/numbat/ref/v1.6.2/">v1.6.2</a><a href="/fork/numbat/ref/v1.6.3/">v1.6.3</a><a href="/fork/numbat/ref/v1.7.0/">v1.7.0</a><a href="/fork/numbat/ref/v1.8.0/">v1.8.0</a><a class="all" href="/fork/numbat/refs">all refs →</a></div></details><nav class="crumbs"><a href="/fork/numbat/">numbat</a> / <a href="/fork/numbat/ref/master/tree/book/">book</a> / <a href="/fork/numbat/ref/master/tree/book/src/">src</a> / <span class="cur">date-and-time.md</span></nav>
<span class="view-stats"><span>6.1 KiB</span><span>108 lines</span></span><span class="actions"><a class="raw" href="/fork/numbat/raw/8512766c497c65e9ef838e69908777b99abb97d1/book/src/date-and-time.md">raw</a></span></header>
<div class="markdown-view"><input type="radio" name="markdown-view" id="markdown-rendered" checked><label for="markdown-rendered">rendered</label><input type="radio" name="markdown-view" id="markdown-code"><label for="markdown-code">code</label><section class="readme rendered"><h1>Date and time</h1>
<p>Numbat supports date and time handling based on the <a href="https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar">proleptic Gregorian calendar</a>,
which is the (usual) Gregorian calendar extended to dates before its introduction in 1582. Julian calendar dates are currently not supported.</p>
<p>A few examples of useful operations that can be performed on dates and times:</p>
<pre># Which date is 40 days from now?
now() + 40 days

# Which date was 1 million seconds ago?
now() - 1 million seconds

# How many days are left until September 1st?
date(&quot;2024-11-01&quot;) - today() -&gt; days

# What time is it in Nepal right now?
now() -&gt; tz(&quot;Asia/Kathmandu&quot;)  # use tab completion to find time zone names

# What is the local time when it is 2024-11-01 12:30:00 in Australia?
datetime(&quot;2024-11-01 12:30:00 Australia/Sydney&quot;) -&gt; local

# What is the current UNIX timestamp?
now() -&gt; unixtime

# What is the date corresponding to the UNIX timestamp 1707568901?
from_unixtime(1707568901)

# How long are one million seconds in days, hours, minutes, seconds
1 million seconds -&gt; human
</pre>
<h2>Date and time arithmetic</h2>
<p>The following operations are supported for <code>DateTime</code> objects:</p>
<table><thead><tr><th>Left</th><th>Operator</th><th>Right</th><th>Result</th></tr></thead><tbody>
<tr><td><code>DateTime</code></td><td><code>-</code></td><td><code>DateTime</code></td><td>Duration between the two dates as a <code>Time</code>. In <code>seconds</code>, by default. Use normal conversion for other time units.</td></tr>
<tr><td><code>DateTime</code></td><td><code>+</code></td><td><code>Time</code></td><td>New <code>DateTime</code> by adding the duration to the date</td></tr>
<tr><td><code>DateTime</code></td><td><code>-</code></td><td><code>Time</code></td><td>New <code>DateTime</code> by subtracting the duration from the date</td></tr>
<tr><td><code>DateTime</code></td><td><code>-&gt;</code></td><td><code>tz("…")</code></td><td>Converts the datetime to the specified time zone. Note that you can use tab-completion for time zone names.</td></tr>
</tbody></table>
&lt;div class="warning"&gt;
<p><strong>Warning</strong>: You can add <code>years</code> or <code>months</code> to a given date (<code>now() + 3 months</code>), but note that the result might not be what you expect.
The unit <code>year</code> is defined as the <em>average</em> length of a year (a <a href="https://en.wikipedia.org/wiki/Tropical_year">tropical year</a>, to be precise), and
<code>month</code> is defined as the <em>average</em> length of a month (1/12 of a <code>year</code>). So this does not take into account the actual length of the months or the leap years.
However, note that adding or subtracting "one year" or "one month" is not a well-defined operation anyway. For example, what should "one month after March 31st"
be? April 30th or May 1st? If your answer is April 30th, then what is "one month after March 30th"? If your answer is May 1st, then what is "one month after
April 1st"?</p>
&lt;/div&gt;
<h2>Date, time, and duration functions</h2>
<p>The following functions are available for date and time handling:</p>
<ul>
<li><code>now() -&gt; DateTime</code>: Returns the current date and time.</li>
<li><code>today() -&gt; DateTime</code>: Returns the current date at midnight (in the local time).</li>
<li><code>datetime(input: String) -&gt; DateTime</code>: Parses a string (date and time) into a <code>DateTime</code> object.</li>
<li><code>date(input: String) -&gt; DateTime</code>: Parses a string (only date) into a <code>DateTime</code> object.</li>
<li><code>time(input: String) -&gt; DateTime</code>: Parses a string (only time) into a <code>DateTime</code> object.</li>
<li><code>format_datetime(format: String, dt: DateTime) -&gt; String</code>: Formats a <code>DateTime</code> object as a string. See <a href="https://docs.rs/chrono/latest/chrono/format/strftime/index.html#specifiers">this page</a> for possible format specifiers.</li>
<li><code>tz(tz: String) -&gt; Fn[(DateTime) -&gt; DateTime]</code>: Returns a timezone conversion function, typically used with the conversion operator (<code>datetime -&gt; tz("Europe/Berlin")</code>)</li>
<li><code>local(dt: DateTime) -&gt; DateTime</code>: Timezone conversion function targeting the users local timezone (<code>datetime -&gt; local</code>)</li>
<li><code>get_local_timezone() -&gt; String</code>: Returns the users local timezone</li>
<li><code>unixtime(dt: DateTime) -&gt; Scalar</code>: Converts a <code>DateTime</code> to a UNIX timestamp.</li>
<li><code>from_unixtime(ut: Scalar) -&gt; DateTime</code>: Converts a UNIX timestamp to a <code>DateTime</code> object.</li>
<li><code>human(duration: Time) -&gt; String</code>: Converts a <code>Time</code> to a human-readable string in days, hours, minutes and seconds</li>
</ul>
<h2>Date time formats</h2>
<p>The following formats are supported by <code>datetime</code>. UTC offsets are mandatory for the RFC 3339 and
RFC 2822 formats. The other formats can optionally include a time zone name or UTC offset. If no time
zone is specified, the local time zone is used.</p>
<table><thead><tr><th>Format</th><th>Examples</th></tr></thead><tbody>
<tr><td><a href="https://tools.ietf.org/html/rfc3339">RFC 3339</a></td><td><code>2024-02-10T12:30:00Z</code>&lt;br&gt;<code>2024-02-10T06:30:00-06:00</code></td></tr>
<tr><td><a href="https://tools.ietf.org/html/rfc2822">RFC 2822</a></td><td><code>Sat, 10 Feb 2024 12:30:00 Z</code>&lt;br&gt;<code>Sat, 10 Feb 2024 06:30:00 -0600</code></td></tr>
<tr><td><code>%Y-%m-%d %H:%M:%S%.f</code></td><td><code>2024-02-10 12:30:00</code>&lt;br&gt;<code>2024-02-10 06:30:00 -0600</code>&lt;br&gt;<code>2024-02-10 07:30:00 US/Eastern</code>&lt;br&gt;<code>2024-02-10 12:30:00.123456</code></td></tr>
<tr><td><code>%Y/%m/%d %H:%M:%S%.f</code></td><td>same, but with <code>/</code> separator</td></tr>
<tr><td><code>%Y-%m-%d %H:%M</code></td><td><code>2024-02-10 12:30</code>&lt;br&gt;<code>2024-02-10 06:30 -0600</code>&lt;br&gt;<code>2024-02-10 07:30 US/Eastern</code></td></tr>
<tr><td><code>%Y/%m/%d %H:%M</code></td><td>same, but with <code>/</code> separator</td></tr>
<tr><td><code>%Y-%m-%d %I:%M:%S%.f %p</code></td><td><code>2024-02-10 12:30:00 PM</code>&lt;br&gt;<code>2024-02-10 06:30:00 AM -0600</code>&lt;br&gt;<code>2024-02-10 07:30:00 AM US/Eastern</code>&lt;br&gt;<code>2024-02-10 12:30:00.123456 PM</code></td></tr>
<tr><td><code>%Y/%m/%d %I:%M:%S%.f %p</code></td><td>same, but with <code>/</code> separator</td></tr>
<tr><td><code>%Y-%m-%d %I:%M %p</code></td><td><code>2024-02-10 12:30 PM</code>&lt;br&gt;<code>2024-02-10 06:30 AM -0600</code>&lt;br&gt;<code>2024-02-10 07:30 AM US/Eastern</code></td></tr>
<tr><td><code>%Y/%m/%d %I:%M %p</code></td><td>same, but with <code>/</code> separator</td></tr>
</tbody></table>
<p>The <code>date</code> function supports the following formats. It returns a <code>DateTime</code> object with the time set to midnight in the
specified timezone (or the local timezone if no timezone is specified).</p>
<table><thead><tr><th>Format</th><th>Examples</th></tr></thead><tbody>
<tr><td><code>%Y-%m-%d</code></td><td><code>2024-02-10</code>&lt;br&gt;<code>2024-02-10 +0100</code>&lt;br&gt;<code>2024-02-10 Europe/Berlin</code></td></tr>
<tr><td><code>%Y/%m/%d</code></td><td><code>2024/02/10</code>&lt;br&gt;<code>2024/02/10 +0100</code>&lt;br&gt;<code>2024/02/10 Europe/Berlin</code></td></tr>
</tbody></table>
<p>The <code>time</code> function supports the following formats. It returns a <code>DateTime</code> object with the date set to the current date.
If no timezone is specified, the local timezone is used.</p>
<table><thead><tr><th>Format</th><th>Examples</th></tr></thead><tbody>
<tr><td><code>%H:%M:%S%.f</code></td><td><code>12:30:00</code>&lt;br&gt;<code>06:30:00 -0600</code>&lt;br&gt;<code>07:30:00 US/Eastern</code>&lt;br&gt;<code>12:30:00.123456</code></td></tr>
<tr><td><code>%H:%M</code></td><td><code>12:30</code>&lt;br&gt;<code>06:30 -0600</code>&lt;br&gt;<code>07:30 US/Eastern</code></td></tr>
<tr><td><code>%I:%M:%S%.f %p</code></td><td><code>12:30:00 PM</code>&lt;br&gt;<code>06:30:00 AM -0600</code>&lt;br&gt;<code>07:30:00 AM US/Eastern</code>&lt;br&gt;<code>12:30:00.123456 PM</code></td></tr>
<tr><td><code>%I:%M %p</code></td><td><code>12:30 PM</code>&lt;br&gt;<code>06:30 AM -0600</code>&lt;br&gt;<code>07:30 AM US/Eastern</code></td></tr>
</tbody></table>
</section><div class="code-panel"><pre class="code src language-markdown"><span class="code-line"><a class="ln" id="L1" href="#L1">1</a><span class="code-text"><a-p>#</a-p> <a-tt>Date and time</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L2" href="#L2">2</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L3" href="#L3">3</a><span class="code-text">Numbat supports date and time handling based on the [proleptic Gregorian calendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar),</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L4" href="#L4">4</a><span class="code-text">which is the (usual) Gregorian calendar extended to dates before its introduction in 1582. Julian calendar dates are currently not supported.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L5" href="#L5">5</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L6" href="#L6">6</a><span class="code-text">A few examples of useful operations that can be performed on dates and times:</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L7" href="#L7">7</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L8" href="#L8">8</a><span class="code-text"><a-p>```</a-p><a-tl>nbt</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L9" href="#L9">9</a><span class="code-text"><a-p># Which date is 40 days from now?</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L10" href="#L10">10</a><span class="code-text"><a-p>now() + 40 days</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L11" href="#L11">11</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L12" href="#L12">12</a><span class="code-text"><a-p># Which date was 1 million seconds ago?</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L13" href="#L13">13</a><span class="code-text"><a-p>now() - 1 million seconds</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L14" href="#L14">14</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L15" href="#L15">15</a><span class="code-text"><a-p># How many days are left until September 1st?</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L16" href="#L16">16</a><span class="code-text"><a-p>date(&quot;2024-11-01&quot;) - today() -&gt; days</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L17" href="#L17">17</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L18" href="#L18">18</a><span class="code-text"><a-p># What time is it in Nepal right now?</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L19" href="#L19">19</a><span class="code-text"><a-p>now() -&gt; tz(&quot;Asia/Kathmandu&quot;)  # use tab completion to find time zone names</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L20" href="#L20">20</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L21" href="#L21">21</a><span class="code-text"><a-p># What is the local time when it is 2024-11-01 12:30:00 in Australia?</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L22" href="#L22">22</a><span class="code-text"><a-p>datetime(&quot;2024-11-01 12:30:00 Australia/Sydney&quot;) -&gt; local</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L23" href="#L23">23</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L24" href="#L24">24</a><span class="code-text"><a-p># What is the current UNIX timestamp?</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L25" href="#L25">25</a><span class="code-text"><a-p>now() -&gt; unixtime</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L26" href="#L26">26</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L27" href="#L27">27</a><span class="code-text"><a-p># What is the date corresponding to the UNIX timestamp 1707568901?</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L28" href="#L28">28</a><span class="code-text"><a-p>from_unixtime(1707568901)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L29" href="#L29">29</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L30" href="#L30">30</a><span class="code-text"><a-p># How long are one million seconds in days, hours, minutes, seconds</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L31" href="#L31">31</a><span class="code-text"><a-p>1 million seconds -&gt; human</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L32" href="#L32">32</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L33" href="#L33">33</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L34" href="#L34">34</a><span class="code-text"><a-p>## </a-p><a-tt>Date and time arithmetic</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L35" href="#L35">35</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L36" href="#L36">36</a><span class="code-text"><a-p>The following operations are supported for `DateTime` objects:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L37" href="#L37">37</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L38" href="#L38">38</a><span class="code-text"><a-p>| Left | Operator | Right | Result |</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L39" href="#L39">39</a><span class="code-text"><a-p>| ---- | -------- | ----- | ------ |</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L40" href="#L40">40</a><span class="code-text"><a-p>| `DateTime` | `-` | `DateTime` | Duration between the two dates as a `Time`. In `seconds`, by default. Use normal conversion for other time units. |</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L41" href="#L41">41</a><span class="code-text"><a-p>| `DateTime` | `+` | `Time` | New `DateTime` by adding the duration to the date |</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L42" href="#L42">42</a><span class="code-text"><a-p>| `DateTime` | `-` | `Time` | New `DateTime` by subtracting the duration from the date |</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L43" href="#L43">43</a><span class="code-text"><a-p>| `DateTime` | `-&gt;` | `tz(&quot;…&quot;)` | Converts the datetime to the specified time zone. Note that you can use tab-completion for time zone names. |</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L44" href="#L44">44</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L45" href="#L45">45</a><span class="code-text"><a-p>&lt;</a-p><a-tg>div</a-tg><a-p> </a-p><a-at>class</a-at><a-p>=&quot;</a-p><a-s>warning</a-s><a-p>&quot;&gt;</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L46" href="#L46">46</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L47" href="#L47">47</a><span class="code-text"><a-p>**Warning**: You can add `years` or `months` to a given date (`now() + 3 months`), but note that the result might not be what you expect.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L48" href="#L48">48</a><span class="code-text"><a-p>The unit `year` is defined as the *average* length of a year (a [tropical year](https://en.wikipedia.org/wiki/Tropical_year), to be precise), and</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L49" href="#L49">49</a><span class="code-text"><a-p>`month` is defined as the *average* length of a month (1/12 of a `year`). So this does not take into account the actual length of the months or the leap years.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L50" href="#L50">50</a><span class="code-text"><a-p>However, note that adding or subtracting &quot;one year&quot; or &quot;one month&quot; is not a well-defined operation anyway. For example, what should &quot;one month after March 31st&quot;</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L51" href="#L51">51</a><span class="code-text"><a-p>be? April 30th or May 1st? If your answer is April 30th, then what is &quot;one month after March 30th&quot;? If your answer is May 1st, then what is &quot;one month after</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L52" href="#L52">52</a><span class="code-text"><a-p>April 1st&quot;?</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L53" href="#L53">53</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L54" href="#L54">54</a><span class="code-text"><a-p>&lt;/div&gt;</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L55" href="#L55">55</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L56" href="#L56">56</a><span class="code-text"><a-p>## </a-p><a-tt>Date, time, and duration functions</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L57" href="#L57">57</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L58" href="#L58">58</a><span class="code-text"><a-p>The following functions are available for date and time handling:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L59" href="#L59">59</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L60" href="#L60">60</a><span class="code-text"><a-p>- `now() -&gt; DateTime`: Returns the current date and time.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L61" href="#L61">61</a><span class="code-text"><a-p>- `today() -&gt; DateTime`: Returns the current date at midnight (in the local time).</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L62" href="#L62">62</a><span class="code-text"><a-p>- `datetime(input: String) -&gt; DateTime`: Parses a string (date and time) into a `DateTime` object.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L63" href="#L63">63</a><span class="code-text"><a-p>- `date(input: String) -&gt; DateTime`: Parses a string (only date) into a `DateTime` object.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L64" href="#L64">64</a><span class="code-text"><a-p>- `time(input: String) -&gt; DateTime`: Parses a string (only time) into a `DateTime` object.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L65" href="#L65">65</a><span class="code-text"><a-p>- `format_datetime(format: String, dt: DateTime) -&gt; String`: Formats a `DateTime` object as a string. See [this page](https://docs.rs/chrono/latest/chrono/format/strftime/index.html#specifiers) for possible format specifiers.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L66" href="#L66">66</a><span class="code-text"><a-p>- `tz(tz: String) -&gt; Fn[(DateTime) -&gt; DateTime]`: Returns a timezone conversion function, typically used with the conversion operator (`datetime -&gt; tz(&quot;Europe/Berlin&quot;)`)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L67" href="#L67">67</a><span class="code-text"><a-p>- `local(dt: DateTime) -&gt; DateTime`: Timezone conversion function targeting the users local timezone (`datetime -&gt; local`)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L68" href="#L68">68</a><span class="code-text"><a-p>- `get_local_timezone() -&gt; String`: Returns the users local timezone</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L69" href="#L69">69</a><span class="code-text"><a-p>- `unixtime(dt: DateTime) -&gt; Scalar`: Converts a `DateTime` to a UNIX timestamp.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L70" href="#L70">70</a><span class="code-text"><a-p>- `from_unixtime(ut: Scalar) -&gt; DateTime`: Converts a UNIX timestamp to a `DateTime` object.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L71" href="#L71">71</a><span class="code-text"><a-p>- `human(duration: Time) -&gt; String`: Converts a `Time` to a human-readable string in days, hours, minutes and seconds</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L72" href="#L72">72</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L73" href="#L73">73</a><span class="code-text"><a-p>## </a-p><a-tt>Date time formats</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L74" href="#L74">74</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L75" href="#L75">75</a><span class="code-text">The following formats are supported by `datetime`. UTC offsets are mandatory for the RFC 3339 and</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L76" href="#L76">76</a><span class="code-text">RFC 2822 formats. The other formats can optionally include a time zone name or UTC offset. If no time</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L77" href="#L77">77</a><span class="code-text">zone is specified, the local time zone is used.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L78" href="#L78">78</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L79" href="#L79">79</a><span class="code-text">| Format | Examples |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L80" href="#L80">80</a><span class="code-text">| ------ | ------- |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L81" href="#L81">81</a><span class="code-text">| [RFC 3339](https://tools.ietf.org/html/rfc3339) | `2024-02-10T12:30:00Z`&lt;br&gt;`2024-02-10T06:30:00-06:00` |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L82" href="#L82">82</a><span class="code-text">| [RFC 2822](https://tools.ietf.org/html/rfc2822) | `Sat, 10 Feb 2024 12:30:00 Z`&lt;br&gt;`Sat, 10 Feb 2024 06:30:00 -0600` |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L83" href="#L83">83</a><span class="code-text">| `%Y-%m-%d %H:%M:%S%.f` | `2024-02-10 12:30:00`&lt;br&gt;`2024-02-10 06:30:00 -0600`&lt;br&gt;`2024-02-10 07:30:00 US/Eastern`&lt;br&gt;`2024-02-10 12:30:00.123456` |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L84" href="#L84">84</a><span class="code-text">| `%Y/%m/%d %H:%M:%S%.f` | same, but with `/` separator |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L85" href="#L85">85</a><span class="code-text">| `%Y-%m-%d %H:%M` | `2024-02-10 12:30`&lt;br&gt;`2024-02-10 06:30 -0600`&lt;br&gt;`2024-02-10 07:30 US/Eastern` |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L86" href="#L86">86</a><span class="code-text">| `%Y/%m/%d %H:%M` | same, but with `/` separator |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L87" href="#L87">87</a><span class="code-text">| `%Y-%m-%d %I:%M:%S%.f %p` | `2024-02-10 12:30:00 PM`&lt;br&gt;`2024-02-10 06:30:00 AM -0600`&lt;br&gt;`2024-02-10 07:30:00 AM US/Eastern`&lt;br&gt;`2024-02-10 12:30:00.123456 PM` |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L88" href="#L88">88</a><span class="code-text">| `%Y/%m/%d %I:%M:%S%.f %p` | same, but with `/` separator |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L89" href="#L89">89</a><span class="code-text">| `%Y-%m-%d %I:%M %p` | `2024-02-10 12:30 PM`&lt;br&gt;`2024-02-10 06:30 AM -0600`&lt;br&gt;`2024-02-10 07:30 AM US/Eastern` |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L90" href="#L90">90</a><span class="code-text">| `%Y/%m/%d %I:%M %p` | same, but with `/` separator |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L91" href="#L91">91</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L92" href="#L92">92</a><span class="code-text">The `date` function supports the following formats. It returns a `DateTime` object with the time set to midnight in the</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L93" href="#L93">93</a><span class="code-text">specified timezone (or the local timezone if no timezone is specified).</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L94" href="#L94">94</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L95" href="#L95">95</a><span class="code-text">| Format | Examples |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L96" href="#L96">96</a><span class="code-text">| ------ | ------- |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L97" href="#L97">97</a><span class="code-text">| `%Y-%m-%d` | `2024-02-10`&lt;br&gt;`2024-02-10 +0100`&lt;br&gt;`2024-02-10 Europe/Berlin` |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L98" href="#L98">98</a><span class="code-text">| `%Y/%m/%d` | `2024/02/10`&lt;br&gt;`2024/02/10 +0100`&lt;br&gt;`2024/02/10 Europe/Berlin` |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L99" href="#L99">99</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L100" href="#L100">100</a><span class="code-text">The `time` function supports the following formats. It returns a `DateTime` object with the date set to the current date.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L101" href="#L101">101</a><span class="code-text">If no timezone is specified, the local timezone is used.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L102" href="#L102">102</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L103" href="#L103">103</a><span class="code-text">| Format | Examples |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L104" href="#L104">104</a><span class="code-text">| ------ | ------- |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L105" href="#L105">105</a><span class="code-text">| `%H:%M:%S%.f` | `12:30:00`&lt;br&gt;`06:30:00 -0600`&lt;br&gt;`07:30:00 US/Eastern`&lt;br&gt;`12:30:00.123456` |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L106" href="#L106">106</a><span class="code-text">| `%H:%M` | `12:30`&lt;br&gt;`06:30 -0600`&lt;br&gt;`07:30 US/Eastern` |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L107" href="#L107">107</a><span class="code-text">| `%I:%M:%S%.f %p` | `12:30:00 PM`&lt;br&gt;`06:30:00 AM -0600`&lt;br&gt;`07:30:00 AM US/Eastern`&lt;br&gt;`12:30:00.123456 PM` |</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L108" href="#L108">108</a><span class="code-text">| `%I:%M %p` | `12:30 PM`&lt;br&gt;`06:30 AM -0600`&lt;br&gt;`07:30 AM US/Eastern` |</span></span></pre></div></div>
</main>
</body>
</html>
