mentat/chrono/naive/struct.NaiveDate.html

1048 lines
189 KiB
HTML
Raw Permalink Normal View History

2018-08-22 17:04:13 +00:00
<!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="API documentation for the Rust `NaiveDate` struct in crate `chrono`.">
<meta name="keywords" content="rust, rustlang, rust-lang, NaiveDate">
<title>chrono::naive::NaiveDate - Rust</title>
<link rel="stylesheet" type="text/css" href="../../normalize.css">
<link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle">
<link rel="stylesheet" type="text/css" href="../../dark.css">
<link rel="stylesheet" type="text/css" href="../../main.css" id="themeStyle">
<script src="../../storage.js"></script>
</head>
<body class="rustdoc struct">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
<div class="sidebar-menu">&#9776;</div>
<p class='location'>Struct NaiveDate</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.from_ymd">from_ymd</a><a href="#method.from_ymd_opt">from_ymd_opt</a><a href="#method.from_yo">from_yo</a><a href="#method.from_yo_opt">from_yo_opt</a><a href="#method.from_isoywd">from_isoywd</a><a href="#method.from_isoywd_opt">from_isoywd_opt</a><a href="#method.from_num_days_from_ce">from_num_days_from_ce</a><a href="#method.from_num_days_from_ce_opt">from_num_days_from_ce_opt</a><a href="#method.parse_from_str">parse_from_str</a><a href="#method.and_time">and_time</a><a href="#method.and_hms">and_hms</a><a href="#method.and_hms_opt">and_hms_opt</a><a href="#method.and_hms_milli">and_hms_milli</a><a href="#method.and_hms_milli_opt">and_hms_milli_opt</a><a href="#method.and_hms_micro">and_hms_micro</a><a href="#method.and_hms_micro_opt">and_hms_micro_opt</a><a href="#method.and_hms_nano">and_hms_nano</a><a href="#method.and_hms_nano_opt">and_hms_nano_opt</a><a href="#method.succ">succ</a><a href="#method.succ_opt">succ_opt</a><a href="#method.pred">pred</a><a href="#method.pred_opt">pred_opt</a><a href="#method.checked_add_signed">checked_add_signed</a><a href="#method.checked_sub_signed">checked_sub_signed</a><a href="#method.signed_duration_since">signed_duration_since</a><a href="#method.format_with_items">format_with_items</a><a href="#method.format">format</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Serialize">Serialize</a><a href="#impl-Deserialize%3C%27de%3E">Deserialize&lt;&#39;de&gt;</a><a href="#impl-PartialEq">PartialEq</a><a href="#impl-Eq">Eq</a><a href="#impl-Hash">Hash</a><a href="#impl-PartialOrd">PartialOrd</a><a href="#impl-Ord">Ord</a><a href="#impl-Copy">Copy</a><a href="#impl-Clone">Clone</a><a href="#impl-Datelike">Datelike</a><a href="#impl-Add%3COldDuration%3E">Add&lt;OldDuration&gt;</a><a href="#impl-AddAssign%3COldDuration%3E">AddAssign&lt;OldDuration&gt;</a><a href="#impl-Sub%3COldDuration%3E">Sub&lt;OldDuration&gt;</a><a href="#impl-SubAssign%3COldDuration%3E">SubAssign&lt;OldDuration&gt;</a><a href="#impl-Sub%3CNaiveDate%3E">Sub&lt;NaiveDate&gt;</a><a href="#impl-Debug">Debug</a><a href="#impl-Display">Display</a><a href="#impl-FromStr">FromStr</a></div></div><p class='location'><a href='../index.html'>chrono</a>::<wbr><a href='index.html'>naive</a></p><script>window.sidebarCurrent = {name: 'NaiveDate', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div>
</nav>
<div class="theme-picker">
<button id="theme-picker" aria-label="Pick another theme!">
<img src="../../brush.svg" width="18" alt="Pick another theme!">
</button>
<div id="theme-choices"></div>
</div>
<script src="../../theme.js"></script>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content">
<h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>chrono</a>::<wbr><a href='index.html'>naive</a>::<wbr><a class="struct" href=''>NaiveDate</a></span><span class='out-of-band'><span id='render-detail'>
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
[<span class='inner'>&#x2212;</span>]
</a>
</span><a class='srclink' href='../../src/chrono/naive/date.rs.html#97-99' title='goto source code'>[src]</a></span></h1>
<pre class='rust struct'>pub struct NaiveDate { /* fields omitted */ }</pre><div class='docblock'><p>ISO 8601 calendar date without timezone.
Allows for every <a href="#calendar-date">proleptic Gregorian date</a>
from Jan 1, 262145 BCE to Dec 31, 262143 CE.
Also supports the conversion from ISO 8601 ordinal and week date.</p>
<h1 id="calendar-date" class="section-header"><a href="#calendar-date">Calendar Date</a></h1>
<p>The ISO 8601 <strong>calendar date</strong> follows the proleptic Gregorian calendar.
It is like a normal civil calendar but note some slight differences:</p>
<ul>
<li>
<p>Dates before the Gregorian calendar's inception in 1582 are defined via the extrapolation.
Be careful, as historical dates are often noted in the Julian calendar and others
and the transition to Gregorian may differ across countries (as late as early 20C).</p>
<p>(Some example: Both Shakespeare from Britain and Cervantes from Spain seemingly died
on the same calendar date---April 23, 1616---but in the different calendar.
Britain used the Julian calendar at that time, so Shakespeare's death is later.)</p>
</li>
<li>
<p>ISO 8601 calendars has the year 0, which is 1 BCE (a year before 1 CE).
If you need a typical BCE/BC and CE/AD notation for year numbers,
use the <a href="../trait.Datelike.html#method.year_ce"><code>Datelike::year_ce</code></a> method.</p>
</li>
</ul>
<h1 id="week-date" class="section-header"><a href="#week-date">Week Date</a></h1>
<p>The ISO 8601 <strong>week date</strong> is a triple of year number, week number
and <a href="../enum.Weekday.html">day of the week</a> with the following rules:</p>
<ul>
<li>
<p>A week consists of Monday through Sunday, and is always numbered within some year.
The week number ranges from 1 to 52 or 53 depending on the year.</p>
</li>
<li>
<p>The week 1 of given year is defined as the first week containing January 4 of that year,
or equivalently, the first week containing four or more days in that year.</p>
</li>
<li>
<p>The year number in the week date may <em>not</em> correspond to the actual Gregorian year.
For example, January 3, 2016 (Sunday) was on the last (53rd) week of 2015.</p>
</li>
</ul>
<p>Chrono's date types default to the ISO 8601 <a href="#calendar-date">calendar date</a>,
but <a href="../trait.Datelike.html#tymethod.iso_week"><code>Datelike::iso_week</code></a> and
<a href="../trait.Datelike.html#tymethod.weekday"><code>Datelike::weekday</code></a> methods
can be used to get the corresponding week date.</p>
<h1 id="ordinal-date" class="section-header"><a href="#ordinal-date">Ordinal Date</a></h1>
<p>The ISO 8601 <strong>ordinal date</strong> is a pair of year number and day of the year (&quot;ordinal&quot;).
The ordinal number ranges from 1 to 365 or 366 depending on the year.
The year number is same to that of the <a href="#calendar-date">calendar date</a>.</p>
<p>This is currently the internal format of Chrono's date types.</p>
</div>
<h2 id='methods' class='small-section-header'>
Methods<a href='#methods' class='anchor'></a>
</h2>
<h3 id='impl' class='impl'><span class='in-band'><code>impl <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#125-961' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.from_ymd' class="method"><span id='from_ymd.v' class='invisible'><code>pub fn <a href='#method.from_ymd' class='fnname'>from_ymd</a>(year: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>, month: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, day: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#161-163' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> from the <a href="#calendar-date">calendar date</a>
(year, month and day).</p>
<p>Panics on the out-of-range date, invalid month and/or day.</p>
<h1 id="example" class="section-header"><a href="#example">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>, <span class="ident">Weekday</span>};
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">3</span>, <span class="number">14</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">year</span>(), <span class="number">2015</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">month</span>(), <span class="number">3</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">day</span>(), <span class="number">14</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">ordinal</span>(), <span class="number">73</span>); <span class="comment">// day of year</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">iso_week</span>().<span class="ident">year</span>(), <span class="number">2015</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">iso_week</span>().<span class="ident">week</span>(), <span class="number">11</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">weekday</span>(), <span class="ident">Weekday</span>::<span class="ident">Sat</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">num_days_from_ce</span>(), <span class="number">735671</span>); <span class="comment">// days since January 1, 1 CE</span></pre>
</div><h4 id='method.from_ymd_opt' class="method"><span id='from_ymd_opt.v' class='invisible'><code>pub fn <a href='#method.from_ymd_opt' class='fnname'>from_ymd_opt</a>(year: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>, month: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, day: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#184-187' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> from the <a href="#calendar-date">calendar date</a>
(year, month and day).</p>
<p>Returns <code>None</code> on the out-of-range date, invalid month and/or day.</p>
<h1 id="example-1" class="section-header"><a href="#example-1">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">let</span> <span class="ident">from_ymd_opt</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd_opt</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">from_ymd_opt</span>(<span class="number">2015</span>, <span class="number">3</span>, <span class="number">14</span>).<span class="ident">is_some</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">from_ymd_opt</span>(<span class="number">2015</span>, <span class="number">0</span>, <span class="number">14</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">from_ymd_opt</span>(<span class="number">2015</span>, <span class="number">2</span>, <span class="number">29</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">from_ymd_opt</span>(<span class="op">-</span><span class="number">4</span>, <span class="number">2</span>, <span class="number">29</span>).<span class="ident">is_some</span>()); <span class="comment">// 5 BCE is a leap year</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">from_ymd_opt</span>(<span class="number">400000</span>, <span class="number">1</span>, <span class="number">1</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">from_ymd_opt</span>(<span class="op">-</span><span class="number">400000</span>, <span class="number">1</span>, <span class="number">1</span>).<span class="ident">is_none</span>());</pre>
</div><h4 id='method.from_yo' class="method"><span id='from_yo.v' class='invisible'><code>pub fn <a href='#method.from_yo' class='fnname'>from_yo</a>(year: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>, ordinal: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#209-211' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> from the <a href="#ordinal-date">ordinal date</a>
(year and day of the year).</p>
<p>Panics on the out-of-range date and/or invalid day of year.</p>
<h1 id="example-2" class="section-header"><a href="#example-2">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>, <span class="ident">Weekday</span>};
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_yo</span>(<span class="number">2015</span>, <span class="number">73</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">ordinal</span>(), <span class="number">73</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">year</span>(), <span class="number">2015</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">month</span>(), <span class="number">3</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">day</span>(), <span class="number">14</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">iso_week</span>().<span class="ident">year</span>(), <span class="number">2015</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">iso_week</span>().<span class="ident">week</span>(), <span class="number">11</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">weekday</span>(), <span class="ident">Weekday</span>::<span class="ident">Sat</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">num_days_from_ce</span>(), <span class="number">735671</span>); <span class="comment">// days since January 1, 1 CE</span></pre>
</div><h4 id='method.from_yo_opt' class="method"><span id='from_yo_opt.v' class='invisible'><code>pub fn <a href='#method.from_yo_opt' class='fnname'>from_yo_opt</a>(year: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>, ordinal: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#233-236' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> from the <a href="#ordinal-date">ordinal date</a>
(year and day of the year).</p>
<p>Returns <code>None</code> on the out-of-range date and/or invalid day of year.</p>
<h1 id="example-3" class="section-header"><a href="#example-3">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">let</span> <span class="ident">from_yo_opt</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_yo_opt</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">from_yo_opt</span>(<span class="number">2015</span>, <span class="number">100</span>).<span class="ident">is_some</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">from_yo_opt</span>(<span class="number">2015</span>, <span class="number">0</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">from_yo_opt</span>(<span class="number">2015</span>, <span class="number">365</span>).<span class="ident">is_some</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">from_yo_opt</span>(<span class="number">2015</span>, <span class="number">366</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">from_yo_opt</span>(<span class="op">-</span><span class="number">4</span>, <span class="number">366</span>).<span class="ident">is_some</span>()); <span class="comment">// 5 BCE is a leap year</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">from_yo_opt</span>(<span class="number">400000</span>, <span class="number">1</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">from_yo_opt</span>(<span class="op">-</span><span class="number">400000</span>, <span class="number">1</span>).<span class="ident">is_none</span>());</pre>
</div><h4 id='method.from_isoywd' class="method"><span id='from_isoywd.v' class='invisible'><code>pub fn <a href='#method.from_isoywd' class='fnname'>from_isoywd</a>(year: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>, week: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, weekday: <a class="enum" href="../../chrono/enum.Weekday.html" title="enum chrono::Weekday">Weekday</a>) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#259-261' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> from the <a href="#week-date">ISO week date</a>
(year, week number and day of the week).
The resulting <code>NaiveDate</code> may have a different year from the input year.</p>
<p>Panics on the out-of-range date and/or invalid week number.</p>
<h1 id="example-4" class="section-header"><a href="#example-4">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>, <span class="ident">Weekday</span>};
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_isoywd</span>(<span class="number">2015</span>, <span class="number">11</span>, <span class="ident">Weekday</span>::<span class="ident">Sat</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">iso_week</span>().<span class="ident">year</span>(), <span class="number">2015</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">iso_week</span>().<span class="ident">week</span>(), <span class="number">11</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">weekday</span>(), <span class="ident">Weekday</span>::<span class="ident">Sat</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">year</span>(), <span class="number">2015</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">month</span>(), <span class="number">3</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">day</span>(), <span class="number">14</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">ordinal</span>(), <span class="number">73</span>); <span class="comment">// day of year</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">num_days_from_ce</span>(), <span class="number">735671</span>); <span class="comment">// days since January 1, 1 CE</span></pre>
</div><h4 id='method.from_isoywd_opt' class="method"><span id='from_isoywd_opt.v' class='invisible'><code>pub fn <a href='#method.from_isoywd_opt' class='fnname'>from_isoywd_opt</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;year: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;week: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;weekday: <a class="enum" href="../../chrono/enum.Weekday.html" title="enum chrono::Weekday">Weekday</a><br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#307-331' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> from the <a href="#week-date">ISO week date</a>
(year, week number and day of the week).
The resulting <code>NaiveDate</code> may have a different year from the input year.</p>
<p>Returns <code>None</code> on the out-of-range date and/or invalid week number.</p>
<h1 id="example-5" class="section-header"><a href="#example-5">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Weekday</span>};
<span class="kw">let</span> <span class="ident">from_ymd</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>;
<span class="kw">let</span> <span class="ident">from_isoywd_opt</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_isoywd_opt</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_isoywd_opt</span>(<span class="number">2015</span>, <span class="number">0</span>, <span class="ident">Weekday</span>::<span class="ident">Sun</span>), <span class="prelude-val">None</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_isoywd_opt</span>(<span class="number">2015</span>, <span class="number">10</span>, <span class="ident">Weekday</span>::<span class="ident">Sun</span>), <span class="prelude-val">Some</span>(<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">3</span>, <span class="number">8</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_isoywd_opt</span>(<span class="number">2015</span>, <span class="number">30</span>, <span class="ident">Weekday</span>::<span class="ident">Mon</span>), <span class="prelude-val">Some</span>(<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">7</span>, <span class="number">20</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_isoywd_opt</span>(<span class="number">2015</span>, <span class="number">60</span>, <span class="ident">Weekday</span>::<span class="ident">Mon</span>), <span class="prelude-val">None</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_isoywd_opt</span>(<span class="number">400000</span>, <span class="number">10</span>, <span class="ident">Weekday</span>::<span class="ident">Fri</span>), <span class="prelude-val">None</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_isoywd_opt</span>(<span class="op">-</span><span class="number">400000</span>, <span class="number">10</span>, <span class="ident">Weekday</span>::<span class="ident">Sat</span>), <span class="prelude-val">None</span>);</pre>
<p>The year number of ISO week date may differ from that of the calendar date.</p>
<pre class="rust rust-example-rendered">
<span class="comment">// Mo Tu We Th Fr Sa Su</span>
<span class="comment">// 2014-W52 22 23 24 25 26 27 28 has 4+ days of new year,</span>
<span class="comment">// 2015-W01 29 30 31 1 2 3 4 &lt;- so this is the first week</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_isoywd_opt</span>(<span class="number">2014</span>, <span class="number">52</span>, <span class="ident">Weekday</span>::<span class="ident">Sun</span>), <span class="prelude-val">Some</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">12</span>, <span class="number">28</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_isoywd_opt</span>(<span class="number">2014</span>, <span class="number">53</span>, <span class="ident">Weekday</span>::<span class="ident">Mon</span>), <span class="prelude-val">None</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_isoywd_opt</span>(<span class="number">2015</span>, <span class="number">1</span>, <span class="ident">Weekday</span>::<span class="ident">Mon</span>), <span class="prelude-val">Some</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">12</span>, <span class="number">29</span>)));
<span class="comment">// 2015-W52 21 22 23 24 25 26 27 has 4+ days of old year,</span>
<span class="comment">// 2015-W53 28 29 30 31 1 2 3 &lt;- so this is the last week</span>
<span class="comment">// 2016-W01 4 5 6 7 8 9 10</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_isoywd_opt</span>(<span class="number">2015</span>, <span class="number">52</span>, <span class="ident">Weekday</span>::<span class="ident">Sun</span>), <span class="prelude-val">Some</span>(<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">12</span>, <span class="number">27</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_isoywd_opt</span>(<span class="number">2015</span>, <span class="number">53</span>, <span class="ident">Weekday</span>::<span class="ident">Sun</span>), <span class="prelude-val">Some</span>(<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">1</span>, <span class="number">3</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_isoywd_opt</span>(<span class="number">2015</span>, <span class="number">54</span>, <span class="ident">Weekday</span>::<span class="ident">Mon</span>), <span class="prelude-val">None</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_isoywd_opt</span>(<span class="number">2016</span>, <span class="number">1</span>, <span class="ident">Weekday</span>::<span class="ident">Mon</span>), <span class="prelude-val">Some</span>(<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">1</span>, <span class="number">4</span>)));</pre>
</div><h4 id='method.from_num_days_from_ce' class="method"><span id='from_num_days_from_ce.v' class='invisible'><code>pub fn <a href='#method.from_num_days_from_ce' class='fnname'>from_num_days_from_ce</a>(days: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#377-379' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> from the number of days since January 1, 1 (Day 1)
in the proleptic Gregorian calendar.</p>
<p>Panics on the out-of-range date.</p>
<h1 id="example-6" class="section-header"><a href="#example-6">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>, <span class="ident">Weekday</span>};
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_num_days_from_ce</span>(<span class="number">735671</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">num_days_from_ce</span>(), <span class="number">735671</span>); <span class="comment">// days since January 1, 1 CE</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">year</span>(), <span class="number">2015</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">month</span>(), <span class="number">3</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">day</span>(), <span class="number">14</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">ordinal</span>(), <span class="number">73</span>); <span class="comment">// day of year</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">iso_week</span>().<span class="ident">year</span>(), <span class="number">2015</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">iso_week</span>().<span class="ident">week</span>(), <span class="number">11</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">weekday</span>(), <span class="ident">Weekday</span>::<span class="ident">Sat</span>);</pre>
<p>While not directly supported by Chrono,
it is easy to convert from the Julian day number
(January 1, 4713 BCE in the <em>Julian</em> calendar being Day 0)
to Gregorian with this method.
(Note that this panics when <code>jd</code> is out of range.)</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">fn</span> <span class="ident">jd_to_date</span>(<span class="ident">jd</span>: <span class="ident">i32</span>) <span class="op">-&gt;</span> <span class="ident">NaiveDate</span> {
<span class="comment">// keep in mind that the Julian day number is 0-based</span>
<span class="comment">// while this method requires an 1-based number.</span>
<span class="ident">NaiveDate</span>::<span class="ident">from_num_days_from_ce</span>(<span class="ident">jd</span> <span class="op">-</span> <span class="number">1721425</span>)
}
<span class="comment">// January 1, 4713 BCE in Julian = November 24, 4714 BCE in Gregorian</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">jd_to_date</span>(<span class="number">0</span>), <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="op">-</span><span class="number">4713</span>, <span class="number">11</span>, <span class="number">24</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">jd_to_date</span>(<span class="number">1721426</span>), <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">jd_to_date</span>(<span class="number">2450000</span>), <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">1995</span>, <span class="number">10</span>, <span class="number">9</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">jd_to_date</span>(<span class="number">2451545</span>), <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2000</span>, <span class="number">1</span>, <span class="number">1</span>));</pre>
</div><h4 id='method.from_num_days_from_ce_opt' class="method"><span id='from_num_days_from_ce_opt.v' class='invisible'><code>pub fn <a href='#method.from_num_days_from_ce_opt' class='fnname'>from_num_days_from_ce_opt</a>(days: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#401-408' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> from the number of days since January 1, 1 (Day 1)
in the proleptic Gregorian calendar.</p>
<p>Returns <code>None</code> on the out-of-range date.</p>
<h1 id="example-7" class="section-header"><a href="#example-7">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">let</span> <span class="ident">from_ndays_opt</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_num_days_from_ce_opt</span>;
<span class="kw">let</span> <span class="ident">from_ymd</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ndays_opt</span>(<span class="number">730_000</span>), <span class="prelude-val">Some</span>(<span class="ident">from_ymd</span>(<span class="number">1999</span>, <span class="number">9</span>, <span class="number">3</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ndays_opt</span>(<span class="number">1</span>), <span class="prelude-val">Some</span>(<span class="ident">from_ymd</span>(<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ndays_opt</span>(<span class="number">0</span>), <span class="prelude-val">Some</span>(<span class="ident">from_ymd</span>(<span class="number">0</span>, <span class="number">12</span>, <span class="number">31</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ndays_opt</span>(<span class="op">-</span><span class="number">1</span>), <span class="prelude-val">Some</span>(<span class="ident">from_ymd</span>(<span class="number">0</span>, <span class="number">12</span>, <span class="number">30</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ndays_opt</span>(<span class="number">100_000_000</span>), <span class="prelude-val">None</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ndays_opt</span>(<span class="op">-</span><span class="number">100_000_000</span>), <span class="prelude-val">None</span>);</pre>
</div><h4 id='method.parse_from_str' class="method"><span id='parse_from_str.v' class='invisible'><code>pub fn <a href='#method.parse_from_str' class='fnname'>parse_from_str</a>(s: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>, fmt: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="type" href="../../chrono/format/type.ParseResult.html" title="type chrono::format::ParseResult">ParseResult</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#452-456' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Parses a string with the specified format string and returns a new <code>NaiveDate</code>.
See the <a href="../format/strftime/index.html"><code>format::strftime</code> module</a>
on the supported escape sequences.</p>
<h1 id="example-8" class="section-header"><a href="#example-8">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">let</span> <span class="ident">parse_from_str</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">parse_from_str</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">parse_from_str</span>(<span class="string">&quot;2015-09-05&quot;</span>, <span class="string">&quot;%Y-%m-%d&quot;</span>),
<span class="prelude-val">Ok</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">5</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">parse_from_str</span>(<span class="string">&quot;5sep2015&quot;</span>, <span class="string">&quot;%d%b%Y&quot;</span>),
<span class="prelude-val">Ok</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">5</span>)));</pre>
<p>Time and offset is ignored for the purpose of parsing.</p>
<pre class="rust rust-example-rendered">
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">parse_from_str</span>(<span class="string">&quot;2014-5-17T12:34:56+09:30&quot;</span>, <span class="string">&quot;%Y-%m-%dT%H:%M:%S%z&quot;</span>),
<span class="prelude-val">Ok</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">5</span>, <span class="number">17</span>)));</pre>
<p>Out-of-bound dates or insufficient fields are errors.</p>
<pre class="rust rust-example-rendered">
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">parse_from_str</span>(<span class="string">&quot;2015/9&quot;</span>, <span class="string">&quot;%Y/%m&quot;</span>).<span class="ident">is_err</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">parse_from_str</span>(<span class="string">&quot;2015/9/31&quot;</span>, <span class="string">&quot;%Y/%m/%d&quot;</span>).<span class="ident">is_err</span>());</pre>
<p>All parsed fields should be consistent to each other, otherwise it's an error.</p>
<pre class="rust rust-example-rendered">
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">parse_from_str</span>(<span class="string">&quot;Sat, 09 Aug 2013&quot;</span>, <span class="string">&quot;%a, %d %b %Y&quot;</span>).<span class="ident">is_err</span>());</pre>
</div><h4 id='method.and_time' class="method"><span id='and_time.v' class='invisible'><code>pub fn <a href='#method.and_time' class='fnname'>and_time</a>(&amp;self, time: <a class="struct" href="../../chrono/naive/struct.NaiveTime.html" title="struct chrono::naive::NaiveTime">NaiveTime</a>) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#473-475' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDateTime</code> from the current date and given <code>NaiveTime</code>.</p>
<h1 id="example-9" class="section-header"><a href="#example-9">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">NaiveTime</span>, <span class="ident">NaiveDateTime</span>};
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>);
<span class="kw">let</span> <span class="ident">t</span> <span class="op">=</span> <span class="ident">NaiveTime</span>::<span class="ident">from_hms_milli</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>);
<span class="kw">let</span> <span class="ident">dt</span>: <span class="ident">NaiveDateTime</span> <span class="op">=</span> <span class="ident">d</span>.<span class="ident">and_time</span>(<span class="ident">t</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">date</span>(), <span class="ident">d</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">time</span>(), <span class="ident">t</span>);</pre>
</div><h4 id='method.and_hms' class="method"><span id='and_hms.v' class='invisible'><code>pub fn <a href='#method.and_hms' class='fnname'>and_hms</a>(&amp;self, hour: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, min: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, sec: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#497-499' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDateTime</code> from the current date, hour, minute and second.</p>
<p>No <a href="./struct.NaiveTime.html#leap-second-handling">leap second</a> is allowed here;
use <code>NaiveDate::and_hms_*</code> methods with a subsecond parameter instead.</p>
<p>Panics on invalid hour, minute and/or second.</p>
<h1 id="example-10" class="section-header"><a href="#example-10">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">NaiveDateTime</span>, <span class="ident">Datelike</span>, <span class="ident">Timelike</span>, <span class="ident">Weekday</span>};
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>);
<span class="kw">let</span> <span class="ident">dt</span>: <span class="ident">NaiveDateTime</span> <span class="op">=</span> <span class="ident">d</span>.<span class="ident">and_hms</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">year</span>(), <span class="number">2015</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">weekday</span>(), <span class="ident">Weekday</span>::<span class="ident">Wed</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">second</span>(), <span class="number">56</span>);</pre>
</div><h4 id='method.and_hms_opt' class="method"><span id='and_hms_opt.v' class='invisible'><code>pub fn <a href='#method.and_hms_opt' class='fnname'>and_hms_opt</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;hour: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;min: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;sec: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a><br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#520-522' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDateTime</code> from the current date, hour, minute and second.</p>
<p>No <a href="./struct.NaiveTime.html#leap-second-handling">leap second</a> is allowed here;
use <code>NaiveDate::and_hms_*_opt</code> methods with a subsecond parameter instead.</p>
<p>Returns <code>None</code> on invalid hour, minute and/or second.</p>
<h1 id="example-11" class="section-header"><a href="#example-11">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>).<span class="ident">is_some</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">60</span>).<span class="ident">is_none</span>()); <span class="comment">// use `and_hms_milli_opt` instead</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_opt</span>(<span class="number">12</span>, <span class="number">60</span>, <span class="number">56</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_opt</span>(<span class="number">24</span>, <span class="number">34</span>, <span class="number">56</span>).<span class="ident">is_none</span>());</pre>
</div><h4 id='method.and_hms_milli' class="method"><span id='and_hms_milli.v' class='invisible'><code>pub fn <a href='#method.and_hms_milli' class='fnname'>and_hms_milli</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;hour: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;min: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;sec: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;milli: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a><br>) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#545-547' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDateTime</code> from the current date, hour, minute, second and millisecond.</p>
<p>The millisecond part can exceed 1,000
in order to represent the <a href="./struct.NaiveTime.html#leap-second-handling">leap second</a>.</p>
<p>Panics on invalid hour, minute, second and/or millisecond.</p>
<h1 id="example-12" class="section-header"><a href="#example-12">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">NaiveDateTime</span>, <span class="ident">Datelike</span>, <span class="ident">Timelike</span>, <span class="ident">Weekday</span>};
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>);
<span class="kw">let</span> <span class="ident">dt</span>: <span class="ident">NaiveDateTime</span> <span class="op">=</span> <span class="ident">d</span>.<span class="ident">and_hms_milli</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">year</span>(), <span class="number">2015</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">weekday</span>(), <span class="ident">Weekday</span>::<span class="ident">Wed</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">second</span>(), <span class="number">56</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">nanosecond</span>(), <span class="number">789_000_000</span>);</pre>
</div><h4 id='method.and_hms_milli_opt' class="method"><span id='and_hms_milli_opt.v' class='invisible'><code>pub fn <a href='#method.and_hms_milli_opt' class='fnname'>and_hms_milli_opt</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;hour: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;min: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;sec: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;milli: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a><br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#570-573' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDateTime</code> from the current date, hour, minute, second and millisecond.</p>
<p>The millisecond part can exceed 1,000
in order to represent the <a href="./struct.NaiveTime.html#leap-second-handling">leap second</a>.</p>
<p>Returns <code>None</code> on invalid hour, minute, second and/or millisecond.</p>
<h1 id="example-13" class="section-header"><a href="#example-13">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_milli_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>).<span class="ident">is_some</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_milli_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">59</span>, <span class="number">1_789</span>).<span class="ident">is_some</span>()); <span class="comment">// leap second</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_milli_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">59</span>, <span class="number">2_789</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_milli_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">60</span>, <span class="number">789</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_milli_opt</span>(<span class="number">12</span>, <span class="number">60</span>, <span class="number">56</span>, <span class="number">789</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_milli_opt</span>(<span class="number">24</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789</span>).<span class="ident">is_none</span>());</pre>
</div><h4 id='method.and_hms_micro' class="method"><span id='and_hms_micro.v' class='invisible'><code>pub fn <a href='#method.and_hms_micro' class='fnname'>and_hms_micro</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;hour: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;min: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;sec: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;micro: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a><br>) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#596-598' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDateTime</code> from the current date, hour, minute, second and microsecond.</p>
<p>The microsecond part can exceed 1,000,000
in order to represent the <a href="./struct.NaiveTime.html#leap-second-handling">leap second</a>.</p>
<p>Panics on invalid hour, minute, second and/or microsecond.</p>
<h1 id="example-14" class="section-header"><a href="#example-14">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">NaiveDateTime</span>, <span class="ident">Datelike</span>, <span class="ident">Timelike</span>, <span class="ident">Weekday</span>};
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>);
<span class="kw">let</span> <span class="ident">dt</span>: <span class="ident">NaiveDateTime</span> <span class="op">=</span> <span class="ident">d</span>.<span class="ident">and_hms_micro</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789_012</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">year</span>(), <span class="number">2015</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">weekday</span>(), <span class="ident">Weekday</span>::<span class="ident">Wed</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">second</span>(), <span class="number">56</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">nanosecond</span>(), <span class="number">789_012_000</span>);</pre>
</div><h4 id='method.and_hms_micro_opt' class="method"><span id='and_hms_micro_opt.v' class='invisible'><code>pub fn <a href='#method.and_hms_micro_opt' class='fnname'>and_hms_micro_opt</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;hour: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;min: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;sec: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;micro: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a><br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#621-624' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDateTime</code> from the current date, hour, minute, second and microsecond.</p>
<p>The microsecond part can exceed 1,000,000
in order to represent the <a href="./struct.NaiveTime.html#leap-second-handling">leap second</a>.</p>
<p>Returns <code>None</code> on invalid hour, minute, second and/or microsecond.</p>
<h1 id="example-15" class="section-header"><a href="#example-15">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_micro_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789_012</span>).<span class="ident">is_some</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_micro_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">59</span>, <span class="number">1_789_012</span>).<span class="ident">is_some</span>()); <span class="comment">// leap second</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_micro_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">59</span>, <span class="number">2_789_012</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_micro_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">60</span>, <span class="number">789_012</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_micro_opt</span>(<span class="number">12</span>, <span class="number">60</span>, <span class="number">56</span>, <span class="number">789_012</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_micro_opt</span>(<span class="number">24</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789_012</span>).<span class="ident">is_none</span>());</pre>
</div><h4 id='method.and_hms_nano' class="method"><span id='and_hms_nano.v' class='invisible'><code>pub fn <a href='#method.and_hms_nano' class='fnname'>and_hms_nano</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;hour: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;min: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;sec: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;nano: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a><br>) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#647-649' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDateTime</code> from the current date, hour, minute, second and nanosecond.</p>
<p>The nanosecond part can exceed 1,000,000,000
in order to represent the <a href="./struct.NaiveTime.html#leap-second-handling">leap second</a>.</p>
<p>Panics on invalid hour, minute, second and/or nanosecond.</p>
<h1 id="example-16" class="section-header"><a href="#example-16">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">NaiveDateTime</span>, <span class="ident">Datelike</span>, <span class="ident">Timelike</span>, <span class="ident">Weekday</span>};
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>);
<span class="kw">let</span> <span class="ident">dt</span>: <span class="ident">NaiveDateTime</span> <span class="op">=</span> <span class="ident">d</span>.<span class="ident">and_hms_nano</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789_012_345</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">year</span>(), <span class="number">2015</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">weekday</span>(), <span class="ident">Weekday</span>::<span class="ident">Wed</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">second</span>(), <span class="number">56</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">dt</span>.<span class="ident">nanosecond</span>(), <span class="number">789_012_345</span>);</pre>
</div><h4 id='method.and_hms_nano_opt' class="method"><span id='and_hms_nano_opt.v' class='invisible'><code>pub fn <a href='#method.and_hms_nano_opt' class='fnname'>and_hms_nano_opt</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self, <br>&nbsp;&nbsp;&nbsp;&nbsp;hour: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;min: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;sec: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;nano: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a><br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDateTime.html" title="struct chrono::naive::NaiveDateTime">NaiveDateTime</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#672-675' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDateTime</code> from the current date, hour, minute, second and nanosecond.</p>
<p>The nanosecond part can exceed 1,000,000,000
in order to represent the <a href="./struct.NaiveTime.html#leap-second-handling">leap second</a>.</p>
<p>Returns <code>None</code> on invalid hour, minute, second and/or nanosecond.</p>
<h1 id="example-17" class="section-header"><a href="#example-17">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_nano_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789_012_345</span>).<span class="ident">is_some</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_nano_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">59</span>, <span class="number">1_789_012_345</span>).<span class="ident">is_some</span>()); <span class="comment">// leap second</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_nano_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">59</span>, <span class="number">2_789_012_345</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_nano_opt</span>(<span class="number">12</span>, <span class="number">34</span>, <span class="number">60</span>, <span class="number">789_012_345</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_nano_opt</span>(<span class="number">12</span>, <span class="number">60</span>, <span class="number">56</span>, <span class="number">789_012_345</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">and_hms_nano_opt</span>(<span class="number">24</span>, <span class="number">34</span>, <span class="number">56</span>, <span class="number">789_012_345</span>).<span class="ident">is_none</span>());</pre>
</div><h4 id='method.succ' class="method"><span id='succ.v' class='invisible'><code>pub fn <a href='#method.succ' class='fnname'>succ</a>(&amp;self) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#724-726' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> for the next calendar date.</p>
<p>Panics when <code>self</code> is the last representable date.</p>
<h1 id="example-18" class="section-header"><a href="#example-18">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>).<span class="ident">succ</span>(), <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">4</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">30</span>).<span class="ident">succ</span>(), <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">7</span>, <span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">12</span>, <span class="number">31</span>).<span class="ident">succ</span>(), <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">1</span>, <span class="number">1</span>));</pre>
</div><h4 id='method.succ_opt' class="method"><span id='succ_opt.v' class='invisible'><code>pub fn <a href='#method.succ_opt' class='fnname'>succ_opt</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#743-745' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> for the next calendar date.</p>
<p>Returns <code>None</code> when <code>self</code> is the last representable date.</p>
<h1 id="example-19" class="section-header"><a href="#example-19">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">naive</span>::<span class="ident">MAX_DATE</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>).<span class="ident">succ_opt</span>(),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">4</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">MAX_DATE</span>.<span class="ident">succ_opt</span>(), <span class="prelude-val">None</span>);</pre>
</div><h4 id='method.pred' class="method"><span id='pred.v' class='invisible'><code>pub fn <a href='#method.pred' class='fnname'>pred</a>(&amp;self) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#761-763' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> for the previous calendar date.</p>
<p>Panics when <code>self</code> is the first representable date.</p>
<h1 id="example-20" class="section-header"><a href="#example-20">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>).<span class="ident">pred</span>(), <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">2</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">1</span>).<span class="ident">pred</span>(), <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">5</span>, <span class="number">31</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">1</span>, <span class="number">1</span>).<span class="ident">pred</span>(), <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">12</span>, <span class="number">31</span>));</pre>
</div><h4 id='method.pred_opt' class="method"><span id='pred_opt.v' class='invisible'><code>pub fn <a href='#method.pred_opt' class='fnname'>pred_opt</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#780-782' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> for the previous calendar date.</p>
<p>Returns <code>None</code> when <code>self</code> is the first representable date.</p>
<h1 id="example-21" class="section-header"><a href="#example-21">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">naive</span>::<span class="ident">MIN_DATE</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">3</span>).<span class="ident">pred_opt</span>(),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">6</span>, <span class="number">2</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">MIN_DATE</span>.<span class="ident">pred_opt</span>(), <span class="prelude-val">None</span>);</pre>
</div><h4 id='method.checked_add_signed' class="method"><span id='checked_add_signed.v' class='invisible'><code>pub fn <a href='#method.checked_add_signed' class='fnname'>checked_add_signed</a>(self, rhs: <a class="struct" href="../../chrono/struct.Duration.html" title="struct chrono::Duration">OldDuration</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#806-818' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Adds the <code>days</code> part of given <code>Duration</code> to the current date.</p>
<p>Returns <code>None</code> when it will result in overflow.</p>
<h1 id="example-22" class="section-header"><a href="#example-22">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">naive</span>::<span class="ident">MAX_DATE</span>;
<span class="kw">use</span> <span class="ident">time</span>::<span class="ident">Duration</span>;
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">5</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">checked_add_signed</span>(<span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">40</span>)),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">10</span>, <span class="number">15</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">checked_add_signed</span>(<span class="ident">Duration</span>::<span class="ident">days</span>(<span class="op">-</span><span class="number">40</span>)),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">7</span>, <span class="number">27</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">checked_add_signed</span>(<span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">1_000_000_000</span>)), <span class="prelude-val">None</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">checked_add_signed</span>(<span class="ident">Duration</span>::<span class="ident">days</span>(<span class="op">-</span><span class="number">1_000_000_000</span>)), <span class="prelude-val">None</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">MAX_DATE</span>.<span class="ident">checked_add_signed</span>(<span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">1</span>)), <span class="prelude-val">None</span>);</pre>
</div><h4 id='method.checked_sub_signed' class="method"><span id='checked_sub_signed.v' class='invisible'><code>pub fn <a href='#method.checked_sub_signed' class='fnname'>checked_sub_signed</a>(self, rhs: <a class="struct" href="../../chrono/struct.Duration.html" title="struct chrono::Duration">OldDuration</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#842-854' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Subtracts the <code>days</code> part of given <code>Duration</code> from the current date.</p>
<p>Returns <code>None</code> when it will result in overflow.</p>
<h1 id="example-23" class="section-header"><a href="#example-23">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">naive</span>::<span class="ident">MIN_DATE</span>;
<span class="kw">use</span> <span class="ident">time</span>::<span class="ident">Duration</span>;
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">5</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">checked_sub_signed</span>(<span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">40</span>)),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">7</span>, <span class="number">27</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">checked_sub_signed</span>(<span class="ident">Duration</span>::<span class="ident">days</span>(<span class="op">-</span><span class="number">40</span>)),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">10</span>, <span class="number">15</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">checked_sub_signed</span>(<span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">1_000_000_000</span>)), <span class="prelude-val">None</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">checked_sub_signed</span>(<span class="ident">Duration</span>::<span class="ident">days</span>(<span class="op">-</span><span class="number">1_000_000_000</span>)), <span class="prelude-val">None</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">MIN_DATE</span>.<span class="ident">checked_sub_signed</span>(<span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">1</span>)), <span class="prelude-val">None</span>);</pre>
</div><h4 id='method.signed_duration_since' class="method"><span id='signed_duration_since.v' class='invisible'><code>pub fn <a href='#method.signed_duration_since' class='fnname'>signed_duration_since</a>(self, rhs: <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>) -&gt; <a class="struct" href="../../chrono/struct.Duration.html" title="struct chrono::Duration">OldDuration</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#881-890' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Subtracts another <code>NaiveDate</code> from the current date.
Returns a <code>Duration</code> of integral numbers.</p>
<p>This does not overflow or underflow at all,
as all possible output fits in the range of <code>Duration</code>.</p>
<h1 id="example-24" class="section-header"><a href="#example-24">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">use</span> <span class="ident">time</span>::<span class="ident">Duration</span>;
<span class="kw">let</span> <span class="ident">from_ymd</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>;
<span class="kw">let</span> <span class="ident">since</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">signed_duration_since</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">since</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>), <span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>)), <span class="ident">Duration</span>::<span class="ident">zero</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">since</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>), <span class="ident">from_ymd</span>(<span class="number">2013</span>, <span class="number">12</span>, <span class="number">31</span>)), <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">since</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>), <span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">2</span>)), <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="op">-</span><span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">since</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>), <span class="ident">from_ymd</span>(<span class="number">2013</span>, <span class="number">9</span>, <span class="number">23</span>)), <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">100</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">since</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>), <span class="ident">from_ymd</span>(<span class="number">2013</span>, <span class="number">1</span>, <span class="number">1</span>)), <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">365</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">since</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>), <span class="ident">from_ymd</span>(<span class="number">2010</span>, <span class="number">1</span>, <span class="number">1</span>)), <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">365</span><span class="kw-2">*</span><span class="number">4</span> <span class="op">+</span> <span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">since</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>), <span class="ident">from_ymd</span>(<span class="number">1614</span>, <span class="number">1</span>, <span class="number">1</span>)), <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">365</span><span class="kw-2">*</span><span class="number">400</span> <span class="op">+</span> <span class="number">97</span>));</pre>
</div><h4 id='method.format_with_items' class="method"><span id='format_with_items.v' class='invisible'><code>pub fn <a href='#method.format_with_items' class='fnname'>format_with_items</a>&lt;'a, I&gt;(&amp;self, items: I) -&gt; <a class="struct" href="../../chrono/format/struct.DelayedFormat.html" title="struct chrono::format::DelayedFormat">DelayedFormat</a>&lt;I&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a>&lt;Item = <a class="enum" href="../../chrono/format/enum.Item.html" title="enum chrono::format::Item">Item</a>&lt;'a&gt;&gt; + <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#920-923' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Formats the date with the specified formatting items.
Otherwise it is same to the ordinary <code>format</code> method.</p>
<p>The <code>Iterator</code> of items should be <code>Clone</code>able,
since the resulting <code>DelayedFormat</code> value may be formatted multiple times.</p>
<h1 id="example-25" class="section-header"><a href="#example-25">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">format</span>::<span class="ident">strftime</span>::<span class="ident">StrftimeItems</span>;
<span class="kw">let</span> <span class="ident">fmt</span> <span class="op">=</span> <span class="ident">StrftimeItems</span>::<span class="ident">new</span>(<span class="string">&quot;%Y-%m-%d&quot;</span>);
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">5</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">format_with_items</span>(<span class="ident">fmt</span>.<span class="ident">clone</span>()).<span class="ident">to_string</span>(), <span class="string">&quot;2015-09-05&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">format</span>(<span class="string">&quot;%Y-%m-%d&quot;</span>).<span class="ident">to_string</span>(), <span class="string">&quot;2015-09-05&quot;</span>);</pre>
<p>The resulting <code>DelayedFormat</code> can be formatted directly via the <code>Display</code> trait.</p>
<pre class="rust rust-example-rendered">
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">d</span>.<span class="ident">format_with_items</span>(<span class="ident">fmt</span>)), <span class="string">&quot;2015-09-05&quot;</span>);</pre>
</div><h4 id='method.format' class="method"><span id='format.v' class='invisible'><code>pub fn <a href='#method.format' class='fnname'>format</a>&lt;'a&gt;(&amp;self, fmt: &amp;'a <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="struct" href="../../chrono/format/struct.DelayedFormat.html" title="struct chrono::format::DelayedFormat">DelayedFormat</a>&lt;<a class="struct" href="../../chrono/format/strftime/struct.StrftimeItems.html" title="struct chrono::format::strftime::StrftimeItems">StrftimeItems</a>&lt;'a&gt;&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#958-960' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Formats the date with the specified format string.
See the <a href="../format/strftime/index.html"><code>format::strftime</code> module</a>
on the supported escape sequences.</p>
<p>This returns a <code>DelayedFormat</code>,
which gets converted to a string only when actual formatting happens.
You may use the <code>to_string</code> method to get a <code>String</code>,
or just feed it into <code>print!</code> and other formatting macros.
(In this way it avoids the redundant memory allocation.)</p>
<p>A wrong format string does <em>not</em> issue an error immediately.
Rather, converting or formatting the <code>DelayedFormat</code> fails.
You are recommended to immediately use <code>DelayedFormat</code> for this reason.</p>
<h1 id="example-26" class="section-header"><a href="#example-26">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">5</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">format</span>(<span class="string">&quot;%Y-%m-%d&quot;</span>).<span class="ident">to_string</span>(), <span class="string">&quot;2015-09-05&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">d</span>.<span class="ident">format</span>(<span class="string">&quot;%A, %-d %B, %C%y&quot;</span>).<span class="ident">to_string</span>(), <span class="string">&quot;Saturday, 5 September, 2015&quot;</span>);</pre>
<p>The resulting <code>DelayedFormat</code> can be formatted directly via the <code>Display</code> trait.</p>
<pre class="rust rust-example-rendered">
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">d</span>.<span class="ident">format</span>(<span class="string">&quot;%Y-%m-%d&quot;</span>)), <span class="string">&quot;2015-09-05&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">d</span>.<span class="ident">format</span>(<span class="string">&quot;%A, %-d %B, %C%y&quot;</span>)), <span class="string">&quot;Saturday, 5 September, 2015&quot;</span>);</pre>
</div></div>
<h2 id='implementations' class='small-section-header'>
Trait Implementations<a href='#implementations' class='anchor'></a>
</h2>
<h3 id='impl-Serialize' class='impl'><span class='in-band'><code>impl <a class="trait" href="../../serde/ser/trait.Serialize.html" title="trait serde::ser::Serialize">Serialize</a> for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-Serialize' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1609-1625' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.serialize' class="method"><span id='serialize.v' class='invisible'><code>fn <a href='../../serde/ser/trait.Serialize.html#tymethod.serialize' class='fnname'>serialize</a>&lt;S&gt;(&amp;self, serializer: S) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;S::<a class="type" href="../../serde/ser/trait.Serializer.html#associatedtype.Ok" title="type serde::ser::Serializer::Ok">Ok</a>, S::<a class="type" href="../../serde/ser/trait.Serializer.html#associatedtype.Error" title="type serde::ser::Serializer::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../serde/ser/trait.Serializer.html" title="trait serde::ser::Serializer">Serializer</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1610-1624' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Serialize this value into the given Serde serializer. <a href="../../serde/ser/trait.Serialize.html#tymethod.serialize">Read more</a></p>
</div></div><h3 id='impl-Deserialize%3C%27de%3E' class='impl'><span class='in-band'><code>impl&lt;'de&gt; <a class="trait" href="../../serde/de/trait.Deserialize.html" title="trait serde::de::Deserialize">Deserialize</a>&lt;'de&gt; for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-Deserialize%3C%27de%3E' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1644-1650' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.deserialize' class="method"><span id='deserialize.v' class='invisible'><code>fn <a href='../../serde/de/trait.Deserialize.html#tymethod.deserialize' class='fnname'>deserialize</a>&lt;D&gt;(deserializer: D) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self, D::<a class="type" href="../../serde/de/trait.Deserializer.html#associatedtype.Error" title="type serde::de::Deserializer::Error">Error</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;D: <a class="trait" href="../../serde/de/trait.Deserializer.html" title="trait serde::de::Deserializer">Deserializer</a>&lt;'de&gt;,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1645-1649' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Deserialize this value from the given Serde deserializer. <a href="../../serde/de/trait.Deserialize.html#tymethod.deserialize">Read more</a></p>
</div></div><h3 id='impl-PartialEq' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a> for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-PartialEq' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.eq' class="method"><span id='eq.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used by <code>==</code>. <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div><h4 id='method.ne' class="method"><span id='ne.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 id='impl-Eq' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-Eq' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'></div><h3 id='impl-Hash' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-Hash' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.hash' class="method"><span id='hash.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html#tymethod.hash' class='fnname'>hash</a>&lt;__H:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>&gt;(&amp;self, __arg_0: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>__H)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Feeds this value into the given [<code>Hasher</code>]. <a href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html#tymethod.hash">Read more</a></p>
</div><h4 id='method.hash_slice' class="method"><span id='hash_slice.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html#method.hash_slice' class='fnname'>hash_slice</a>&lt;H&gt;(data: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.slice.html">&amp;[Self]</a>, state: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>H) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;H: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hasher.html" title="trait core::hash::Hasher">Hasher</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/hash/mod.rs.html#202-208' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Feeds a slice of this type into the given [<code>Hasher</code>]. <a href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html#method.hash_slice">Read more</a></p>
</div></div><h3 id='impl-PartialOrd' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-PartialOrd' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.partial_cmp' class="method"><span id='partial_cmp.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html#tymethod.partial_cmp' class='fnname'>partial_cmp</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>This method returns an ordering between <code>self</code> and <code>other</code> values if one exists. <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html#tymethod.partial_cmp">Read more</a></p>
</div><h4 id='method.lt' class="method"><span id='lt.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html#method.lt' class='fnname'>lt</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>This method tests less than (for <code>self</code> and <code>other</code>) and is used by the <code>&lt;</code> operator. <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html#method.lt">Read more</a></p>
</div><h4 id='method.le' class="method"><span id='le.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html#method.le' class='fnname'>le</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>This method tests less than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code>&lt;=</code> operator. <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html#method.le">Read more</a></p>
</div><h4 id='method.gt' class="method"><span id='gt.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html#method.gt' class='fnname'>gt</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>This method tests greater than (for <code>self</code> and <code>other</code>) and is used by the <code>&gt;</code> operator. <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html#method.gt">Read more</a></p>
</div><h4 id='method.ge' class="method"><span id='ge.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html#method.ge' class='fnname'>ge</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>This method tests greater than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code>&gt;=</code> operator. <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html#method.ge">Read more</a></p>
</div></div><h3 id='impl-Ord' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a> for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-Ord' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.cmp' class="method"><span id='cmp.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html#tymethod.cmp' class='fnname'>cmp</a>(&amp;self, __arg_0: &amp;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/cmp/enum.Ordering.html" title="enum core::cmp::Ordering">Ordering</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>This method returns an <code>Ordering</code> between <code>self</code> and <code>other</code>. <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html#tymethod.cmp">Read more</a></p>
</div><h4 id='method.max' class="method"><span id='max.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html#method.max' class='fnname'>max</a>(self, other: Self) -&gt; Self</code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.21.0'>1.21.0</div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/cmp.rs.html#460-463' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Compares and returns the maximum of two values. <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html#method.max">Read more</a></p>
</div><h4 id='method.min' class="method"><span id='min.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html#method.min' class='fnname'>min</a>(self, other: Self) -&gt; Self</code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.21.0'>1.21.0</div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/cmp.rs.html#476-479' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Compares and returns the minimum of two values. <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html#method.min">Read more</a></p>
</div></div><h3 id='impl-Copy' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a> for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-Copy' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'></div><h3 id='impl-Clone' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-Clone' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.clone' class="method"><span id='clone.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&amp;self) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#96' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Returns a copy of the value. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone">Read more</a></p>
</div><h4 id='method.clone_from' class="method"><span id='clone_from.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&amp;mut self, source: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>Self)</code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.0.0'>1.0.0</div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/core/clone.rs.html#112-114' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from">Read more</a></p>
</div></div><h3 id='impl-Datelike' class='impl'><span class='in-band'><code>impl <a class="trait" href="../../chrono/trait.Datelike.html" title="trait chrono::Datelike">Datelike</a> for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-Datelike' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#963-1303' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.year' class="method"><span id='year.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.year' class='fnname'>year</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#975-977' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Returns the year number in the <a href="#calendar-date">calendar date</a>.</p>
<h1 id="example-27" class="section-header"><a href="#example-27">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">year</span>(), <span class="number">2015</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="op">-</span><span class="number">308</span>, <span class="number">3</span>, <span class="number">14</span>).<span class="ident">year</span>(), <span class="op">-</span><span class="number">308</span>); <span class="comment">// 309 BCE</span></pre>
</div><h4 id='method.month' class="method"><span id='month.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.month' class='fnname'>month</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#992-994' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Returns the month number starting from 1.</p>
<p>The return value ranges from 1 to 12.</p>
<h1 id="example-28" class="section-header"><a href="#example-28">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">month</span>(), <span class="number">9</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="op">-</span><span class="number">308</span>, <span class="number">3</span>, <span class="number">14</span>).<span class="ident">month</span>(), <span class="number">3</span>);</pre>
</div><h4 id='method.month0' class="method"><span id='month0.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.month0' class='fnname'>month0</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1009-1011' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Returns the month number starting from 0.</p>
<p>The return value ranges from 0 to 11.</p>
<h1 id="example-29" class="section-header"><a href="#example-29">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">month0</span>(), <span class="number">8</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="op">-</span><span class="number">308</span>, <span class="number">3</span>, <span class="number">14</span>).<span class="ident">month0</span>(), <span class="number">2</span>);</pre>
</div><h4 id='method.day' class="method"><span id='day.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.day' class='fnname'>day</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1049-1051' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Returns the day of month starting from 1.</p>
<p>The return value ranges from 1 to 31. (The last day of month differs by months.)</p>
<h1 id="example-30" class="section-header"><a href="#example-30">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">day</span>(), <span class="number">8</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="op">-</span><span class="number">308</span>, <span class="number">3</span>, <span class="number">14</span>).<span class="ident">day</span>(), <span class="number">14</span>);</pre>
<p>Combined with <a href="#method.pred"><code>NaiveDate::pred</code></a>,
one can determine the number of days in a particular month.
(Note that this panics when <code>year</code> is out of range.)</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="kw">fn</span> <span class="ident">ndays_in_month</span>(<span class="ident">year</span>: <span class="ident">i32</span>, <span class="ident">month</span>: <span class="ident">u32</span>) <span class="op">-&gt;</span> <span class="ident">u32</span> {
<span class="comment">// the first day of the next month...</span>
<span class="kw">let</span> (<span class="ident">y</span>, <span class="ident">m</span>) <span class="op">=</span> <span class="kw">if</span> <span class="ident">month</span> <span class="op">==</span> <span class="number">12</span> { (<span class="ident">year</span> <span class="op">+</span> <span class="number">1</span>, <span class="number">1</span>) } <span class="kw">else</span> { (<span class="ident">year</span>, <span class="ident">month</span> <span class="op">+</span> <span class="number">1</span>) };
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="ident">y</span>, <span class="ident">m</span>, <span class="number">1</span>);
<span class="comment">// ...is preceded by the last day of the original month</span>
<span class="ident">d</span>.<span class="ident">pred</span>().<span class="ident">day</span>()
}
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">ndays_in_month</span>(<span class="number">2015</span>, <span class="number">8</span>), <span class="number">31</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">ndays_in_month</span>(<span class="number">2015</span>, <span class="number">9</span>), <span class="number">30</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">ndays_in_month</span>(<span class="number">2015</span>, <span class="number">12</span>), <span class="number">31</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">ndays_in_month</span>(<span class="number">2016</span>, <span class="number">2</span>), <span class="number">29</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">ndays_in_month</span>(<span class="number">2017</span>, <span class="number">2</span>), <span class="number">28</span>);</pre>
</div><h4 id='method.day0' class="method"><span id='day0.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.day0' class='fnname'>day0</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1066-1068' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Returns the day of month starting from 0.</p>
<p>The return value ranges from 0 to 30. (The last day of month differs by months.)</p>
<h1 id="example-31" class="section-header"><a href="#example-31">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">day0</span>(), <span class="number">7</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="op">-</span><span class="number">308</span>, <span class="number">3</span>, <span class="number">14</span>).<span class="ident">day0</span>(), <span class="number">13</span>);</pre>
</div><h4 id='method.ordinal' class="method"><span id='ordinal.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.ordinal' class='fnname'>ordinal</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1105-1107' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Returns the day of year starting from 1.</p>
<p>The return value ranges from 1 to 366. (The last day of year differs by years.)</p>
<h1 id="example-32" class="section-header"><a href="#example-32">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">ordinal</span>(), <span class="number">251</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="op">-</span><span class="number">308</span>, <span class="number">3</span>, <span class="number">14</span>).<span class="ident">ordinal</span>(), <span class="number">74</span>);</pre>
<p>Combined with <a href="#method.pred"><code>NaiveDate::pred</code></a>,
one can determine the number of days in a particular year.
(Note that this panics when <code>year</code> is out of range.)</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="kw">fn</span> <span class="ident">ndays_in_year</span>(<span class="ident">year</span>: <span class="ident">i32</span>) <span class="op">-&gt;</span> <span class="ident">u32</span> {
<span class="comment">// the first day of the next year...</span>
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="ident">year</span> <span class="op">+</span> <span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>);
<span class="comment">// ...is preceded by the last day of the original year</span>
<span class="ident">d</span>.<span class="ident">pred</span>().<span class="ident">ordinal</span>()
}
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">ndays_in_year</span>(<span class="number">2015</span>), <span class="number">365</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">ndays_in_year</span>(<span class="number">2016</span>), <span class="number">366</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">ndays_in_year</span>(<span class="number">2017</span>), <span class="number">365</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">ndays_in_year</span>(<span class="number">2000</span>), <span class="number">366</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">ndays_in_year</span>(<span class="number">2100</span>), <span class="number">365</span>);</pre>
</div><h4 id='method.ordinal0' class="method"><span id='ordinal0.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.ordinal0' class='fnname'>ordinal0</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1122-1124' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Returns the day of year starting from 0.</p>
<p>The return value ranges from 0 to 365. (The last day of year differs by years.)</p>
<h1 id="example-33" class="section-header"><a href="#example-33">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">ordinal0</span>(), <span class="number">250</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="op">-</span><span class="number">308</span>, <span class="number">3</span>, <span class="number">14</span>).<span class="ident">ordinal0</span>(), <span class="number">73</span>);</pre>
</div><h4 id='method.weekday' class="method"><span id='weekday.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.weekday' class='fnname'>weekday</a>(&amp;self) -&gt; <a class="enum" href="../../chrono/enum.Weekday.html" title="enum chrono::Weekday">Weekday</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1137-1139' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Returns the day of week.</p>
<h1 id="example-34" class="section-header"><a href="#example-34">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>, <span class="ident">Weekday</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">weekday</span>(), <span class="ident">Weekday</span>::<span class="ident">Tue</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="op">-</span><span class="number">308</span>, <span class="number">3</span>, <span class="number">14</span>).<span class="ident">weekday</span>(), <span class="ident">Weekday</span>::<span class="ident">Fri</span>);</pre>
</div><h4 id='method.iso_week' class="method"><span id='iso_week.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.iso_week' class='fnname'>iso_week</a>(&amp;self) -&gt; <a class="struct" href="../../chrono/naive/struct.IsoWeek.html" title="struct chrono::naive::IsoWeek">IsoWeek</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1142-1144' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Returns the ISO week.</p>
</div><h4 id='method.with_year' class="method"><span id='with_year.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.with_year' class='fnname'>with_year</a>(&amp;self, year: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1169-1178' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> with the year number changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDate</code> would be invalid.</p>
<h1 id="example-35" class="section-header"><a href="#example-35">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">with_year</span>(<span class="number">2016</span>),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">9</span>, <span class="number">8</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">with_year</span>(<span class="op">-</span><span class="number">308</span>),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="op">-</span><span class="number">308</span>, <span class="number">9</span>, <span class="number">8</span>)));</pre>
<p>A leap day (February 29) is a good example that this method can return <code>None</code>.</p>
<pre class="rust rust-example-rendered">
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">2</span>, <span class="number">29</span>).<span class="ident">with_year</span>(<span class="number">2015</span>).<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">2</span>, <span class="number">29</span>).<span class="ident">with_year</span>(<span class="number">2020</span>).<span class="ident">is_some</span>());</pre>
</div><h4 id='method.with_month' class="method"><span id='with_month.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.with_month' class='fnname'>with_month</a>(&amp;self, month: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1195-1197' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> with the month number (starting from 1) changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDate</code> would be invalid.</p>
<h1 id="example-36" class="section-header"><a href="#example-36">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">with_month</span>(<span class="number">10</span>),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">10</span>, <span class="number">8</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">with_month</span>(<span class="number">13</span>), <span class="prelude-val">None</span>); <span class="comment">// no month 13</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">30</span>).<span class="ident">with_month</span>(<span class="number">2</span>), <span class="prelude-val">None</span>); <span class="comment">// no February 30</span></pre>
</div><h4 id='method.with_month0' class="method"><span id='with_month0.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.with_month0' class='fnname'>with_month0</a>(&amp;self, month0: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1214-1216' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> with the month number (starting from 0) changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDate</code> would be invalid.</p>
<h1 id="example-37" class="section-header"><a href="#example-37">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">with_month0</span>(<span class="number">9</span>),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">10</span>, <span class="number">8</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">with_month0</span>(<span class="number">12</span>), <span class="prelude-val">None</span>); <span class="comment">// no month 13</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">30</span>).<span class="ident">with_month0</span>(<span class="number">1</span>), <span class="prelude-val">None</span>); <span class="comment">// no February 30</span></pre>
</div><h4 id='method.with_day' class="method"><span id='with_day.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.with_day' class='fnname'>with_day</a>(&amp;self, day: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1233-1235' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> with the day of month (starting from 1) changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDate</code> would be invalid.</p>
<h1 id="example-38" class="section-header"><a href="#example-38">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">with_day</span>(<span class="number">30</span>),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">30</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">with_day</span>(<span class="number">31</span>),
<span class="prelude-val">None</span>); <span class="comment">// no September 31</span></pre>
</div><h4 id='method.with_day0' class="method"><span id='with_day0.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.with_day0' class='fnname'>with_day0</a>(&amp;self, day0: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1252-1254' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> with the day of month (starting from 0) changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDate</code> would be invalid.</p>
<h1 id="example-39" class="section-header"><a href="#example-39">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">with_day0</span>(<span class="number">29</span>),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">30</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">8</span>).<span class="ident">with_day0</span>(<span class="number">30</span>),
<span class="prelude-val">None</span>); <span class="comment">// no September 31</span></pre>
</div><h4 id='method.with_ordinal' class="method"><span id='with_ordinal.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.with_ordinal' class='fnname'>with_ordinal</a>(&amp;self, ordinal: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1276-1278' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> with the day of year (starting from 1) changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDate</code> would be invalid.</p>
<h1 id="example-40" class="section-header"><a href="#example-40">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">1</span>, <span class="number">1</span>).<span class="ident">with_ordinal</span>(<span class="number">60</span>),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">3</span>, <span class="number">1</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">1</span>, <span class="number">1</span>).<span class="ident">with_ordinal</span>(<span class="number">366</span>),
<span class="prelude-val">None</span>); <span class="comment">// 2015 had only 365 days</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">1</span>, <span class="number">1</span>).<span class="ident">with_ordinal</span>(<span class="number">60</span>),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">2</span>, <span class="number">29</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">1</span>, <span class="number">1</span>).<span class="ident">with_ordinal</span>(<span class="number">366</span>),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">12</span>, <span class="number">31</span>)));</pre>
</div><h4 id='method.with_ordinal0' class="method"><span id='with_ordinal0.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#tymethod.with_ordinal0' class='fnname'>with_ordinal0</a>(&amp;self, ordinal0: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1300-1302' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Makes a new <code>NaiveDate</code> with the day of year (starting from 0) changed.</p>
<p>Returns <code>None</code> when the resulting <code>NaiveDate</code> would be invalid.</p>
<h1 id="example-41" class="section-header"><a href="#example-41">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::{<span class="ident">NaiveDate</span>, <span class="ident">Datelike</span>};
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">1</span>, <span class="number">1</span>).<span class="ident">with_ordinal0</span>(<span class="number">59</span>),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">3</span>, <span class="number">1</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">1</span>, <span class="number">1</span>).<span class="ident">with_ordinal0</span>(<span class="number">365</span>),
<span class="prelude-val">None</span>); <span class="comment">// 2015 had only 365 days</span>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">1</span>, <span class="number">1</span>).<span class="ident">with_ordinal0</span>(<span class="number">59</span>),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">2</span>, <span class="number">29</span>)));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">1</span>, <span class="number">1</span>).<span class="ident">with_ordinal0</span>(<span class="number">365</span>),
<span class="prelude-val">Some</span>(<span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2016</span>, <span class="number">12</span>, <span class="number">31</span>)));</pre>
</div><h4 id='method.year_ce' class="method"><span id='year_ce.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#method.year_ce' class='fnname'>year_ce</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a><a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">)</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/lib.rs.html#807-814' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Returns the absolute year number starting from 1 with a boolean flag, which is false when the year predates the epoch (BCE/BC) and true otherwise (CE/AD). <a href="../../chrono/trait.Datelike.html#method.year_ce">Read more</a></p>
</div><h4 id='method.num_days_from_ce' class="method"><span id='num_days_from_ce.v' class='invisible'><code>fn <a href='../../chrono/trait.Datelike.html#method.num_days_from_ce' class='fnname'>num_days_from_ce</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/lib.rs.html#897-909' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Returns the number of days since January 1, Year 1 (aka Day 1) in the proleptic Gregorian calendar. <a href="../../chrono/trait.Datelike.html#method.num_days_from_ce">Read more</a></p>
</div></div><h3 id='impl-Add%3COldDuration%3E' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/arith/trait.Add.html" title="trait core::ops::arith::Add">Add</a>&lt;<a class="struct" href="../../chrono/struct.Duration.html" title="struct chrono::Duration">OldDuration</a>&gt; for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-Add%3COldDuration%3E' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1330-1337' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>An addition of <code>Duration</code> to <code>NaiveDate</code> discards the fractional days,
rounding to the closest integral number of days towards <code>Duration::zero()</code>.</p>
<p>Panics on underflow or overflow.
Use <a href="#method.checked_add_signed"><code>NaiveDate::checked_add_signed</code></a> to detect that.</p>
<h1 id="example-42" class="section-header"><a href="#example-42">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">use</span> <span class="ident">time</span>::<span class="ident">Duration</span>;
<span class="kw">let</span> <span class="ident">from_ymd</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">+</span> <span class="ident">Duration</span>::<span class="ident">zero</span>(), <span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">+</span> <span class="ident">Duration</span>::<span class="ident">seconds</span>(<span class="number">86399</span>), <span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">+</span> <span class="ident">Duration</span>::<span class="ident">seconds</span>(<span class="op">-</span><span class="number">86399</span>), <span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">+</span> <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">1</span>), <span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">2</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">+</span> <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="op">-</span><span class="number">1</span>), <span class="ident">from_ymd</span>(<span class="number">2013</span>, <span class="number">12</span>, <span class="number">31</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">+</span> <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">364</span>), <span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">12</span>, <span class="number">31</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">+</span> <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">365</span><span class="kw-2">*</span><span class="number">4</span> <span class="op">+</span> <span class="number">1</span>), <span class="ident">from_ymd</span>(<span class="number">2018</span>, <span class="number">1</span>, <span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">+</span> <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">365</span><span class="kw-2">*</span><span class="number">400</span> <span class="op">+</span> <span class="number">97</span>), <span class="ident">from_ymd</span>(<span class="number">2414</span>, <span class="number">1</span>, <span class="number">1</span>));</pre>
</div><div class='impl-items'><h4 id='associatedtype.Output' class="type"><span id='Output.t' class='invisible'><code>type <a href='https://doc.rust-lang.org/nightly/core/ops/arith/trait.Add.html#associatedtype.Output' class="type">Output</a> = <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code></span></h4>
<div class='docblock'><p>The resulting type after applying the <code>+</code> operator.</p>
</div><h4 id='method.add' class="method"><span id='add.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/ops/arith/trait.Add.html#tymethod.add' class='fnname'>add</a>(self, rhs: <a class="struct" href="../../chrono/struct.Duration.html" title="struct chrono::Duration">OldDuration</a>) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1334-1336' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Performs the <code>+</code> operation.</p>
</div></div><h3 id='impl-AddAssign%3COldDuration%3E' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/arith/trait.AddAssign.html" title="trait core::ops::arith::AddAssign">AddAssign</a>&lt;<a class="struct" href="../../chrono/struct.Duration.html" title="struct chrono::Duration">OldDuration</a>&gt; for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-AddAssign%3COldDuration%3E' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1339-1344' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.add_assign' class="method"><span id='add_assign.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/ops/arith/trait.AddAssign.html#tymethod.add_assign' class='fnname'>add_assign</a>(&amp;mut self, rhs: <a class="struct" href="../../chrono/struct.Duration.html" title="struct chrono::Duration">OldDuration</a>)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1341-1343' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Performs the <code>+=</code> operation.</p>
</div></div><h3 id='impl-Sub%3COldDuration%3E' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/arith/trait.Sub.html" title="trait core::ops::arith::Sub">Sub</a>&lt;<a class="struct" href="../../chrono/struct.Duration.html" title="struct chrono::Duration">OldDuration</a>&gt; for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-Sub%3COldDuration%3E' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1372-1379' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>A subtraction of <code>Duration</code> from <code>NaiveDate</code> discards the fractional days,
rounding to the closest integral number of days towards <code>Duration::zero()</code>.
It is same to the addition with a negated <code>Duration</code>.</p>
<p>Panics on underflow or overflow.
Use <a href="#method.checked_sub_signed"><code>NaiveDate::checked_sub_signed</code></a> to detect that.</p>
<h1 id="example-43" class="section-header"><a href="#example-43">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">use</span> <span class="ident">time</span>::<span class="ident">Duration</span>;
<span class="kw">let</span> <span class="ident">from_ymd</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">Duration</span>::<span class="ident">zero</span>(), <span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">Duration</span>::<span class="ident">seconds</span>(<span class="number">86399</span>), <span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">Duration</span>::<span class="ident">seconds</span>(<span class="op">-</span><span class="number">86399</span>), <span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">1</span>), <span class="ident">from_ymd</span>(<span class="number">2013</span>, <span class="number">12</span>, <span class="number">31</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="op">-</span><span class="number">1</span>), <span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">2</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">364</span>), <span class="ident">from_ymd</span>(<span class="number">2013</span>, <span class="number">1</span>, <span class="number">2</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">365</span><span class="kw-2">*</span><span class="number">4</span> <span class="op">+</span> <span class="number">1</span>), <span class="ident">from_ymd</span>(<span class="number">2010</span>, <span class="number">1</span>, <span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">365</span><span class="kw-2">*</span><span class="number">400</span> <span class="op">+</span> <span class="number">97</span>), <span class="ident">from_ymd</span>(<span class="number">1614</span>, <span class="number">1</span>, <span class="number">1</span>));</pre>
</div><div class='impl-items'><h4 id='associatedtype.Output-1' class="type"><span id='Output.t-1' class='invisible'><code>type <a href='https://doc.rust-lang.org/nightly/core/ops/arith/trait.Sub.html#associatedtype.Output' class="type">Output</a> = <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code></span></h4>
<div class='docblock'><p>The resulting type after applying the <code>-</code> operator.</p>
</div><h4 id='method.sub' class="method"><span id='sub.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/ops/arith/trait.Sub.html#tymethod.sub' class='fnname'>sub</a>(self, rhs: <a class="struct" href="../../chrono/struct.Duration.html" title="struct chrono::Duration">OldDuration</a>) -&gt; <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1376-1378' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Performs the <code>-</code> operation.</p>
</div></div><h3 id='impl-SubAssign%3COldDuration%3E' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/arith/trait.SubAssign.html" title="trait core::ops::arith::SubAssign">SubAssign</a>&lt;<a class="struct" href="../../chrono/struct.Duration.html" title="struct chrono::Duration">OldDuration</a>&gt; for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-SubAssign%3COldDuration%3E' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1381-1386' title='goto source code'>[src]</a></span></h3>
<div class='impl-items'><h4 id='method.sub_assign' class="method"><span id='sub_assign.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/ops/arith/trait.SubAssign.html#tymethod.sub_assign' class='fnname'>sub_assign</a>(&amp;mut self, rhs: <a class="struct" href="../../chrono/struct.Duration.html" title="struct chrono::Duration">OldDuration</a>)</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1383-1385' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Performs the <code>-=</code> operation.</p>
</div></div><h3 id='impl-Sub%3CNaiveDate%3E' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/arith/trait.Sub.html" title="trait core::ops::arith::Sub">Sub</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt; for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-Sub%3CNaiveDate%3E' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1415-1422' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Subtracts another <code>NaiveDate</code> from the current date.
Returns a <code>Duration</code> of integral numbers.</p>
<p>This does not overflow or underflow at all,
as all possible output fits in the range of <code>Duration</code>.</p>
<p>The implementation is a wrapper around
<a href="#method.signed_duration_since"><code>NaiveDate::signed_duration_since</code></a>.</p>
<h1 id="example-44" class="section-header"><a href="#example-44">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">use</span> <span class="ident">time</span>::<span class="ident">Duration</span>;
<span class="kw">let</span> <span class="ident">from_ymd</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>), <span class="ident">Duration</span>::<span class="ident">zero</span>());
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">from_ymd</span>(<span class="number">2013</span>, <span class="number">12</span>, <span class="number">31</span>), <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">2</span>), <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="op">-</span><span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">from_ymd</span>(<span class="number">2013</span>, <span class="number">9</span>, <span class="number">23</span>), <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">100</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">from_ymd</span>(<span class="number">2013</span>, <span class="number">1</span>, <span class="number">1</span>), <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">365</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">from_ymd</span>(<span class="number">2010</span>, <span class="number">1</span>, <span class="number">1</span>), <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">365</span><span class="kw-2">*</span><span class="number">4</span> <span class="op">+</span> <span class="number">1</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">from_ymd</span>(<span class="number">2014</span>, <span class="number">1</span>, <span class="number">1</span>) <span class="op">-</span> <span class="ident">from_ymd</span>(<span class="number">1614</span>, <span class="number">1</span>, <span class="number">1</span>), <span class="ident">Duration</span>::<span class="ident">days</span>(<span class="number">365</span><span class="kw-2">*</span><span class="number">400</span> <span class="op">+</span> <span class="number">97</span>));</pre>
</div><div class='impl-items'><h4 id='associatedtype.Output-2' class="type"><span id='Output.t-2' class='invisible'><code>type <a href='https://doc.rust-lang.org/nightly/core/ops/arith/trait.Sub.html#associatedtype.Output' class="type">Output</a> = <a class="struct" href="../../chrono/struct.Duration.html" title="struct chrono::Duration">OldDuration</a></code></span></h4>
<div class='docblock'><p>The resulting type after applying the <code>-</code> operator.</p>
</div><h4 id='method.sub-1' class="method"><span id='sub.v-1' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/ops/arith/trait.Sub.html#tymethod.sub' class='fnname'>sub</a>(self, rhs: <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>) -&gt; <a class="struct" href="../../chrono/struct.Duration.html" title="struct chrono::Duration">OldDuration</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1419-1421' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Performs the <code>-</code> operation.</p>
</div></div><h3 id='impl-Debug' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-Debug' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1446-1457' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>The <code>Debug</code> output of the naive date <code>d</code> is same to
<a href="../format/strftime/index.html"><code>d.format(&quot;%Y-%m-%d&quot;)</code></a>.</p>
<p>The string printed can be readily parsed via the <code>parse</code> method on <code>str</code>.</p>
<h1 id="example-45" class="section-header"><a href="#example-45">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">5</span>)), <span class="string">&quot;2015-09-05&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>( <span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>)), <span class="string">&quot;0000-01-01&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">9999</span>, <span class="number">12</span>, <span class="number">31</span>)), <span class="string">&quot;9999-12-31&quot;</span>);</pre>
<p>ISO 8601 requires an explicit sign for years before 1 BCE or after 9999 CE.</p>
<pre class="rust rust-example-rendered">
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>( <span class="op">-</span><span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>)), <span class="string">&quot;-0001-01-01&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">10000</span>, <span class="number">12</span>, <span class="number">31</span>)), <span class="string">&quot;+10000-12-31&quot;</span>);</pre>
</div><div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1447-1456' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
</div></div><h3 id='impl-Display' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-Display' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1481-1483' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>The <code>Display</code> output of the naive date <code>d</code> is same to
<a href="../format/strftime/index.html"><code>d.format(&quot;%Y-%m-%d&quot;)</code></a>.</p>
<p>The string printed can be readily parsed via the <code>parse</code> method on <code>str</code>.</p>
<h1 id="example-46" class="section-header"><a href="#example-46">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">5</span>)), <span class="string">&quot;2015-09-05&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>( <span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>)), <span class="string">&quot;0000-01-01&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">9999</span>, <span class="number">12</span>, <span class="number">31</span>)), <span class="string">&quot;9999-12-31&quot;</span>);</pre>
<p>ISO 8601 requires an explicit sign for years before 1 BCE or after 9999 CE.</p>
<pre class="rust rust-example-rendered">
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>( <span class="op">-</span><span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>)), <span class="string">&quot;-0001-01-01&quot;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="macro">format</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">10000</span>, <span class="number">12</span>, <span class="number">31</span>)), <span class="string">&quot;+10000-12-31&quot;</span>);</pre>
</div><div class='impl-items'><h4 id='method.fmt-1' class="method"><span id='fmt.v-1' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1482' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html#tymethod.fmt">Read more</a></p>
</div></div><h3 id='impl-FromStr' class='impl'><span class='in-band'><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/str/trait.FromStr.html" title="trait core::str::FromStr">FromStr</a> for <a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a></code><a href='#impl-FromStr' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1501-1518' title='goto source code'>[src]</a></span></h3>
<div class='docblock'><p>Parsing a <code>str</code> into a <code>NaiveDate</code> uses the same format,
<a href="../format/strftime/index.html"><code>%Y-%m-%d</code></a>, as in <code>Debug</code> and <code>Display</code>.</p>
<h1 id="example-47" class="section-header"><a href="#example-47">Example</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">chrono</span>::<span class="ident">NaiveDate</span>;
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">2015</span>, <span class="number">9</span>, <span class="number">18</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;2015-09-18&quot;</span>.<span class="ident">parse</span>::<span class="op">&lt;</span><span class="ident">NaiveDate</span><span class="op">&gt;</span>(), <span class="prelude-val">Ok</span>(<span class="ident">d</span>));
<span class="kw">let</span> <span class="ident">d</span> <span class="op">=</span> <span class="ident">NaiveDate</span>::<span class="ident">from_ymd</span>(<span class="number">12345</span>, <span class="number">6</span>, <span class="number">7</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="string">&quot;+12345-6-7&quot;</span>.<span class="ident">parse</span>::<span class="op">&lt;</span><span class="ident">NaiveDate</span><span class="op">&gt;</span>(), <span class="prelude-val">Ok</span>(<span class="ident">d</span>));
<span class="macro">assert</span><span class="macro">!</span>(<span class="string">&quot;foo&quot;</span>.<span class="ident">parse</span>::<span class="op">&lt;</span><span class="ident">NaiveDate</span><span class="op">&gt;</span>().<span class="ident">is_err</span>());</pre>
</div><div class='impl-items'><h4 id='associatedtype.Err' class="type"><span id='Err.t' class='invisible'><code>type <a href='https://doc.rust-lang.org/nightly/core/str/trait.FromStr.html#associatedtype.Err' class="type">Err</a> = <a class="struct" href="../../chrono/format/struct.ParseError.html" title="struct chrono::format::ParseError">ParseError</a></code></span></h4>
<div class='docblock'><p>The associated error which can be returned from parsing.</p>
</div><h4 id='method.from_str' class="method"><span id='from_str.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/str/trait.FromStr.html#tymethod.from_str' class='fnname'>from_str</a>(s: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="type" href="../../chrono/format/type.ParseResult.html" title="type chrono::format::ParseResult">ParseResult</a>&lt;<a class="struct" href="../../chrono/naive/struct.NaiveDate.html" title="struct chrono::naive::NaiveDate">NaiveDate</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/chrono/naive/date.rs.html#1504-1517' title='goto source code'>[src]</a></span></h4>
<div class='docblock'><p>Parses a string <code>s</code> to return a value of this type. <a href="https://doc.rust-lang.org/nightly/core/str/trait.FromStr.html#tymethod.from_str">Read more</a></p>
</div></div></section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt><kbd>?</kbd></dt>
<dd>Show this help dialog</dd>
<dt><kbd>S</kbd></dt>
<dd>Focus the search field</dd>
<dt><kbd></kbd></dt>
<dd>Move up in search results</dd>
<dt><kbd></kbd></dt>
<dd>Move down in search results</dd>
<dt><kbd></kbd></dt>
<dd>Switch tab</dd>
<dt><kbd>&#9166;</kbd></dt>
<dd>Go to active search result</dd>
<dt><kbd>+</kbd></dt>
<dd>Expand all sections</dd>
<dt><kbd>-</kbd></dt>
<dd>Collapse all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../";
window.currentCrate = "chrono";
</script>
<script src="../../main.js"></script>
<script defer src="../../search-index.js"></script>
</body>
</html>