date_component 0.4.8

the missed date_component with chrono. calculate date interval with chrono.
Documentation
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Chrono-TZ"><title>chrono_tz - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-c4dbdcde0fbd8430.css" id="mainThemeStyle"><link rel="stylesheet" id="themeStyle" href="../static.files/light-db279b6232be9c13.css"><link rel="stylesheet" disabled href="../static.files/dark-cf923f49f397b216.css"><link rel="stylesheet" disabled href="../static.files/ayu-be46fdc453a55015.css"><script src="../static.files/storage-3891ce972e3a2bf8.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-98a684e84ae5b08b.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-13285aec31fa243e.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="logo-container" href="../chrono_tz/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../chrono_tz/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2 class="location"><a href="#">Crate chrono_tz</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.8.3</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#modules">Modules</a></li><li><a href="#enums">Enums</a></li><li><a href="#constants">Constants</a></li><li><a href="#statics">Statics</a></li><li><a href="#traits">Traits</a></li><li><a href="#types">Type Definitions</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">chrono_tz</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/chrono_tz/lib.rs.html#1-378">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="chrono-tz"><a href="#chrono-tz">Chrono-TZ</a></h2>
<p><code>Chrono-TZ</code> is a library that provides implementors of the
<a href="https://lifthrasiir.github.io/rust-chrono/chrono/offset/trait.TimeZone.html"><code>TimeZone</code></a> trait for <a href="https://github.com/lifthrasiir/rust-chrono"><code>chrono</code></a>. The
impls are generated by a build script using the <a href="http://www.iana.org/time-zones"><code>IANA database</code></a>
and <a href="https://github.com/rust-datetime/zoneinfo-parse"><code>zoneinfo_parse</code></a>.</p>
<h3 id="examples"><a href="#examples">Examples</a></h3>
<p>Create a time in one timezone and convert it to UTC</p>

<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{TimeZone, Utc};
<span class="kw">use </span>chrono_tz::US::Pacific;

<span class="kw">let </span>pacific_time = Pacific.ymd(<span class="number">1990</span>, <span class="number">5</span>, <span class="number">6</span>).and_hms(<span class="number">12</span>, <span class="number">30</span>, <span class="number">45</span>);
<span class="kw">let </span>utc_time = pacific_time.with_timezone(<span class="kw-2">&amp;</span>Utc);
<span class="macro">assert_eq!</span>(utc_time, Utc.ymd(<span class="number">1990</span>, <span class="number">5</span>, <span class="number">6</span>).and_hms(<span class="number">19</span>, <span class="number">30</span>, <span class="number">45</span>));</code></pre></div>
<p>Create a naive datetime and convert it to a timezone-aware datetime</p>

<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{TimeZone, NaiveDate};
<span class="kw">use </span>chrono_tz::Africa::Johannesburg;

<span class="kw">let </span>naive_dt = NaiveDate::from_ymd(<span class="number">2038</span>, <span class="number">1</span>, <span class="number">19</span>).and_hms(<span class="number">3</span>, <span class="number">14</span>, <span class="number">08</span>);
<span class="kw">let </span>tz_aware = Johannesburg.from_local_datetime(<span class="kw-2">&amp;</span>naive_dt).unwrap();
<span class="macro">assert_eq!</span>(tz_aware.to_string(), <span class="string">&quot;2038-01-19 03:14:08 SAST&quot;</span>);</code></pre></div>
<p>London and New York change their clocks on different days in March
so only have a 4-hour difference on certain days.</p>

<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::TimeZone;
<span class="kw">use </span>chrono_tz::Europe::London;
<span class="kw">use </span>chrono_tz::America::New_York;

<span class="kw">let </span>london_time = London.ymd(<span class="number">2016</span>, <span class="number">3</span>, <span class="number">18</span>).and_hms(<span class="number">3</span>, <span class="number">0</span>, <span class="number">0</span>);
<span class="kw">let </span>ny_time = london_time.with_timezone(<span class="kw-2">&amp;</span>New_York);
<span class="macro">assert_eq!</span>(ny_time, New_York.ymd(<span class="number">2016</span>, <span class="number">3</span>, <span class="number">17</span>).and_hms(<span class="number">23</span>, <span class="number">0</span>, <span class="number">0</span>));</code></pre></div>
<p>Adding 24 hours across a daylight savings change causes a change
in local time</p>

<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::{TimeZone, Duration};
<span class="kw">use </span>chrono_tz::Europe::London;

<span class="kw">let </span>dt = London.ymd(<span class="number">2016</span>, <span class="number">10</span>, <span class="number">29</span>).and_hms(<span class="number">12</span>, <span class="number">0</span>, <span class="number">0</span>);
<span class="kw">let </span>later = dt + Duration::hours(<span class="number">24</span>);
<span class="macro">assert_eq!</span>(later, London.ymd(<span class="number">2016</span>, <span class="number">10</span>, <span class="number">30</span>).and_hms(<span class="number">11</span>, <span class="number">0</span>, <span class="number">0</span>));</code></pre></div>
<p>And of course you can always convert a local time to a unix timestamp</p>

<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::TimeZone;
<span class="kw">use </span>chrono_tz::Asia::Kolkata;

<span class="kw">let </span>dt = Kolkata.ymd(<span class="number">2000</span>, <span class="number">1</span>, <span class="number">1</span>).and_hms(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);
<span class="kw">let </span>timestamp = dt.timestamp();
<span class="macro">assert_eq!</span>(timestamp, <span class="number">946665000</span>);</code></pre></div>
<p>Pretty-printing a string will use the correct abbreviation for the timezone</p>

<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::TimeZone;
<span class="kw">use </span>chrono_tz::Europe::London;

<span class="kw">let </span>dt = London.ymd(<span class="number">2016</span>, <span class="number">5</span>, <span class="number">10</span>).and_hms(<span class="number">12</span>, <span class="number">0</span>, <span class="number">0</span>);
<span class="macro">assert_eq!</span>(dt.to_string(), <span class="string">&quot;2016-05-10 12:00:00 BST&quot;</span>);
<span class="macro">assert_eq!</span>(dt.to_rfc3339(), <span class="string">&quot;2016-05-10T12:00:00+01:00&quot;</span>);</code></pre></div>
<p>You can convert a timezone string to a timezone using the FromStr trait</p>

<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono::TimeZone;
<span class="kw">use </span>chrono_tz::Tz;
<span class="kw">use </span>chrono_tz::UTC;

<span class="kw">let </span>tz: Tz = <span class="string">&quot;Antarctica/South_Pole&quot;</span>.parse().unwrap();
<span class="kw">let </span>dt = tz.ymd(<span class="number">2016</span>, <span class="number">10</span>, <span class="number">22</span>).and_hms(<span class="number">12</span>, <span class="number">0</span>, <span class="number">0</span>);
<span class="kw">let </span>utc = dt.with_timezone(<span class="kw-2">&amp;</span>UTC);
<span class="macro">assert_eq!</span>(utc.to_string(), <span class="string">&quot;2016-10-21 23:00:00 UTC&quot;</span>);</code></pre></div>
<p>If you need to iterate over all variants you can use the TZ_VARIANTS array</p>

<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>chrono_tz::{TZ_VARIANTS, Tz};
<span class="macro">assert!</span>(TZ_VARIANTS.iter().any(|v| <span class="kw-2">*</span>v == Tz::UTC));</code></pre></div>
</div></details><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="Africa/index.html" title="mod chrono_tz::Africa">Africa</a></div></li><li><div class="item-name"><a class="mod" href="America/index.html" title="mod chrono_tz::America">America</a></div></li><li><div class="item-name"><a class="mod" href="Antarctica/index.html" title="mod chrono_tz::Antarctica">Antarctica</a></div></li><li><div class="item-name"><a class="mod" href="Arctic/index.html" title="mod chrono_tz::Arctic">Arctic</a></div></li><li><div class="item-name"><a class="mod" href="Asia/index.html" title="mod chrono_tz::Asia">Asia</a></div></li><li><div class="item-name"><a class="mod" href="Atlantic/index.html" title="mod chrono_tz::Atlantic">Atlantic</a></div></li><li><div class="item-name"><a class="mod" href="Australia/index.html" title="mod chrono_tz::Australia">Australia</a></div></li><li><div class="item-name"><a class="mod" href="Brazil/index.html" title="mod chrono_tz::Brazil">Brazil</a></div></li><li><div class="item-name"><a class="mod" href="Canada/index.html" title="mod chrono_tz::Canada">Canada</a></div></li><li><div class="item-name"><a class="mod" href="Chile/index.html" title="mod chrono_tz::Chile">Chile</a></div></li><li><div class="item-name"><a class="mod" href="Etc/index.html" title="mod chrono_tz::Etc">Etc</a></div></li><li><div class="item-name"><a class="mod" href="Europe/index.html" title="mod chrono_tz::Europe">Europe</a></div></li><li><div class="item-name"><a class="mod" href="Indian/index.html" title="mod chrono_tz::Indian">Indian</a></div></li><li><div class="item-name"><a class="mod" href="Mexico/index.html" title="mod chrono_tz::Mexico">Mexico</a></div></li><li><div class="item-name"><a class="mod" href="Pacific/index.html" title="mod chrono_tz::Pacific">Pacific</a></div></li><li><div class="item-name"><a class="mod" href="US/index.html" title="mod chrono_tz::US">US</a></div></li></ul><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.Tz.html" title="enum chrono_tz::Tz">Tz</a></div><div class="desc docblock-short">TimeZones built at compile time from the tz database</div></li></ul><h2 id="constants" class="small-section-header"><a href="#constants">Constants</a></h2><ul class="item-table"><li><div class="item-name"><a class="constant" href="constant.CET.html" title="constant chrono_tz::CET">CET</a></div></li><li><div class="item-name"><a class="constant" href="constant.CST6CDT.html" title="constant chrono_tz::CST6CDT">CST6CDT</a></div></li><li><div class="item-name"><a class="constant" href="constant.Cuba.html" title="constant chrono_tz::Cuba">Cuba</a></div></li><li><div class="item-name"><a class="constant" href="constant.EET.html" title="constant chrono_tz::EET">EET</a></div></li><li><div class="item-name"><a class="constant" href="constant.EST.html" title="constant chrono_tz::EST">EST</a></div></li><li><div class="item-name"><a class="constant" href="constant.EST5EDT.html" title="constant chrono_tz::EST5EDT">EST5EDT</a></div></li><li><div class="item-name"><a class="constant" href="constant.Egypt.html" title="constant chrono_tz::Egypt">Egypt</a></div></li><li><div class="item-name"><a class="constant" href="constant.Eire.html" title="constant chrono_tz::Eire">Eire</a></div></li><li><div class="item-name"><a class="constant" href="constant.GB.html" title="constant chrono_tz::GB">GB</a></div></li><li><div class="item-name"><a class="constant" href="constant.GBEire.html" title="constant chrono_tz::GBEire">GBEire</a></div></li><li><div class="item-name"><a class="constant" href="constant.GMT.html" title="constant chrono_tz::GMT">GMT</a></div></li><li><div class="item-name"><a class="constant" href="constant.GMT0.html" title="constant chrono_tz::GMT0">GMT0</a></div></li><li><div class="item-name"><a class="constant" href="constant.GMTMinus0.html" title="constant chrono_tz::GMTMinus0">GMTMinus0</a></div></li><li><div class="item-name"><a class="constant" href="constant.GMTPlus0.html" title="constant chrono_tz::GMTPlus0">GMTPlus0</a></div></li><li><div class="item-name"><a class="constant" href="constant.Greenwich.html" title="constant chrono_tz::Greenwich">Greenwich</a></div></li><li><div class="item-name"><a class="constant" href="constant.HST.html" title="constant chrono_tz::HST">HST</a></div></li><li><div class="item-name"><a class="constant" href="constant.Hongkong.html" title="constant chrono_tz::Hongkong">Hongkong</a></div></li><li><div class="item-name"><a class="constant" href="constant.Iceland.html" title="constant chrono_tz::Iceland">Iceland</a></div></li><li><div class="item-name"><a class="constant" href="constant.Iran.html" title="constant chrono_tz::Iran">Iran</a></div></li><li><div class="item-name"><a class="constant" href="constant.Israel.html" title="constant chrono_tz::Israel">Israel</a></div></li><li><div class="item-name"><a class="constant" href="constant.Jamaica.html" title="constant chrono_tz::Jamaica">Jamaica</a></div></li><li><div class="item-name"><a class="constant" href="constant.Japan.html" title="constant chrono_tz::Japan">Japan</a></div></li><li><div class="item-name"><a class="constant" href="constant.Kwajalein.html" title="constant chrono_tz::Kwajalein">Kwajalein</a></div></li><li><div class="item-name"><a class="constant" href="constant.Libya.html" title="constant chrono_tz::Libya">Libya</a></div></li><li><div class="item-name"><a class="constant" href="constant.MET.html" title="constant chrono_tz::MET">MET</a></div></li><li><div class="item-name"><a class="constant" href="constant.MST.html" title="constant chrono_tz::MST">MST</a></div></li><li><div class="item-name"><a class="constant" href="constant.MST7MDT.html" title="constant chrono_tz::MST7MDT">MST7MDT</a></div></li><li><div class="item-name"><a class="constant" href="constant.NZ.html" title="constant chrono_tz::NZ">NZ</a></div></li><li><div class="item-name"><a class="constant" href="constant.NZCHAT.html" title="constant chrono_tz::NZCHAT">NZCHAT</a></div></li><li><div class="item-name"><a class="constant" href="constant.Navajo.html" title="constant chrono_tz::Navajo">Navajo</a></div></li><li><div class="item-name"><a class="constant" href="constant.PRC.html" title="constant chrono_tz::PRC">PRC</a></div></li><li><div class="item-name"><a class="constant" href="constant.PST8PDT.html" title="constant chrono_tz::PST8PDT">PST8PDT</a></div></li><li><div class="item-name"><a class="constant" href="constant.Poland.html" title="constant chrono_tz::Poland">Poland</a></div></li><li><div class="item-name"><a class="constant" href="constant.Portugal.html" title="constant chrono_tz::Portugal">Portugal</a></div></li><li><div class="item-name"><a class="constant" href="constant.ROC.html" title="constant chrono_tz::ROC">ROC</a></div></li><li><div class="item-name"><a class="constant" href="constant.ROK.html" title="constant chrono_tz::ROK">ROK</a></div></li><li><div class="item-name"><a class="constant" href="constant.Singapore.html" title="constant chrono_tz::Singapore">Singapore</a></div></li><li><div class="item-name"><a class="constant" href="constant.Turkey.html" title="constant chrono_tz::Turkey">Turkey</a></div></li><li><div class="item-name"><a class="constant" href="constant.UCT.html" title="constant chrono_tz::UCT">UCT</a></div></li><li><div class="item-name"><a class="constant" href="constant.UTC.html" title="constant chrono_tz::UTC">UTC</a></div></li><li><div class="item-name"><a class="constant" href="constant.Universal.html" title="constant chrono_tz::Universal">Universal</a></div></li><li><div class="item-name"><a class="constant" href="constant.WET.html" title="constant chrono_tz::WET">WET</a></div></li><li><div class="item-name"><a class="constant" href="constant.WSU.html" title="constant chrono_tz::WSU">WSU</a></div></li><li><div class="item-name"><a class="constant" href="constant.Zulu.html" title="constant chrono_tz::Zulu">Zulu</a></div></li></ul><h2 id="statics" class="small-section-header"><a href="#statics">Statics</a></h2><ul class="item-table"><li><div class="item-name"><a class="static" href="static.TZ_VARIANTS.html" title="static chrono_tz::TZ_VARIANTS">TZ_VARIANTS</a></div><div class="desc docblock-short">An array of every known variant</div></li></ul><h2 id="traits" class="small-section-header"><a href="#traits">Traits</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.OffsetComponents.html" title="trait chrono_tz::OffsetComponents">OffsetComponents</a></div><div class="desc docblock-short">Detailed timezone offset components that expose any special conditions currently in effect.</div></li><li><div class="item-name"><a class="trait" href="trait.OffsetName.html" title="trait chrono_tz::OffsetName">OffsetName</a></div><div class="desc docblock-short">Timezone offset name information.</div></li></ul><h2 id="types" class="small-section-header"><a href="#types">Type Definitions</a></h2><ul class="item-table"><li><div class="item-name"><a class="type" href="type.ParseError.html" title="type chrono_tz::ParseError">ParseError</a></div></li></ul></section></div></main><div id="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="chrono_tz" data-themes="" data-resource-suffix="" data-rustdoc-version="1.69.0 (84c898d65 2023-04-16) (built from a source tarball)" data-search-js="search-8a59a8356673ec1f.js" data-settings-js="settings-f0c5c39777a9a2f6.js" data-settings-css="settings-0bcba95ff279c1db.css" ></div></body></html>