Skip to content

Commit

Permalink
Remove superfluous fn main() in doc examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nickelc authored and djc committed Mar 28, 2022
1 parent c9db7d1 commit 0b3a4f5
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 67 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ Addition and subtraction is also supported.
The following illustrates most supported operations to the date and time:

```rust

use chrono::prelude::*;
use chrono::Duration;

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@
//! The following illustrates most supported operations to the date and time:
//!
//! ```rust
//! # fn main() {
//! use chrono::prelude::*;
//! use chrono::Duration;
//!
Expand Down Expand Up @@ -208,7 +207,6 @@
//! Utc.ymd(2001, 9, 9).and_hms(1, 46, 40));
//! assert_eq!(Utc.ymd(1970, 1, 1).and_hms(0, 0, 0) - Duration::seconds(1_000_000_000),
//! Utc.ymd(1938, 4, 24).and_hms(22, 13, 20));
//! # }
//! ```
//!
//! ### Formatting and Parsing
Expand Down
12 changes: 0 additions & 12 deletions src/naive/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,6 @@ impl NaiveDate {
/// # Example
///
/// ```
/// # fn main() {
/// use chrono::{Duration, NaiveDate};
/// use chrono::naive::MAX_DATE;
///
Expand All @@ -890,7 +889,6 @@ impl NaiveDate {
/// assert_eq!(d.checked_add_signed(Duration::days(1_000_000_000)), None);
/// assert_eq!(d.checked_add_signed(Duration::days(-1_000_000_000)), None);
/// assert_eq!(MAX_DATE.checked_add_signed(Duration::days(1)), None);
/// # }
/// ```
pub fn checked_add_signed(self, rhs: OldDuration) -> Option<NaiveDate> {
let year = self.year();
Expand All @@ -912,7 +910,6 @@ impl NaiveDate {
/// # Example
///
/// ```
/// # fn main() {
/// use chrono::{Duration, NaiveDate};
/// use chrono::naive::MIN_DATE;
///
Expand All @@ -924,7 +921,6 @@ impl NaiveDate {
/// assert_eq!(d.checked_sub_signed(Duration::days(1_000_000_000)), None);
/// assert_eq!(d.checked_sub_signed(Duration::days(-1_000_000_000)), None);
/// assert_eq!(MIN_DATE.checked_sub_signed(Duration::days(1)), None);
/// # }
/// ```
pub fn checked_sub_signed(self, rhs: OldDuration) -> Option<NaiveDate> {
let year = self.year();
Expand All @@ -948,7 +944,6 @@ impl NaiveDate {
/// # Example
///
/// ```
/// # fn main() {
/// use chrono::{Duration, NaiveDate};
///
/// let from_ymd = NaiveDate::from_ymd;
Expand All @@ -961,7 +956,6 @@ impl NaiveDate {
/// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2013, 1, 1)), Duration::days(365));
/// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2010, 1, 1)), Duration::days(365*4 + 1));
/// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(1614, 1, 1)), Duration::days(365*400 + 97));
/// # }
/// ```
pub fn signed_duration_since(self, rhs: NaiveDate) -> OldDuration {
let year1 = self.year();
Expand Down Expand Up @@ -1454,7 +1448,6 @@ impl Datelike for NaiveDate {
/// # Example
///
/// ```
/// # fn main() {
/// use chrono::{Duration, NaiveDate};
///
/// let from_ymd = NaiveDate::from_ymd;
Expand All @@ -1467,7 +1460,6 @@ impl Datelike for NaiveDate {
/// assert_eq!(from_ymd(2014, 1, 1) + Duration::days(364), from_ymd(2014, 12, 31));
/// assert_eq!(from_ymd(2014, 1, 1) + Duration::days(365*4 + 1), from_ymd(2018, 1, 1));
/// assert_eq!(from_ymd(2014, 1, 1) + Duration::days(365*400 + 97), from_ymd(2414, 1, 1));
/// # }
/// ```
impl Add<OldDuration> for NaiveDate {
type Output = NaiveDate;
Expand Down Expand Up @@ -1495,7 +1487,6 @@ impl AddAssign<OldDuration> for NaiveDate {
/// # Example
///
/// ```
/// # fn main() {
/// use chrono::{Duration, NaiveDate};
///
/// let from_ymd = NaiveDate::from_ymd;
Expand All @@ -1508,7 +1499,6 @@ impl AddAssign<OldDuration> for NaiveDate {
/// assert_eq!(from_ymd(2014, 1, 1) - Duration::days(364), from_ymd(2013, 1, 2));
/// assert_eq!(from_ymd(2014, 1, 1) - Duration::days(365*4 + 1), from_ymd(2010, 1, 1));
/// assert_eq!(from_ymd(2014, 1, 1) - Duration::days(365*400 + 97), from_ymd(1614, 1, 1));
/// # }
/// ```
impl Sub<OldDuration> for NaiveDate {
type Output = NaiveDate;
Expand Down Expand Up @@ -1538,7 +1528,6 @@ impl SubAssign<OldDuration> for NaiveDate {
/// # Example
///
/// ```
/// # fn main() {
/// use chrono::{Duration, NaiveDate};
///
/// let from_ymd = NaiveDate::from_ymd;
Expand All @@ -1550,7 +1539,6 @@ impl SubAssign<OldDuration> for NaiveDate {
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 1, 1), Duration::days(365));
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2010, 1, 1), Duration::days(365*4 + 1));
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(1614, 1, 1), Duration::days(365*400 + 97));
/// # }
/// ```
impl Sub<NaiveDate> for NaiveDate {
type Output = OldDuration;
Expand Down
28 changes: 0 additions & 28 deletions src/naive/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ impl NaiveDateTime {
/// # Example
///
/// ```
/// # fn main() {
/// use chrono::{Duration, NaiveDate};
///
/// let from_ymd = NaiveDate::from_ymd;
Expand All @@ -489,24 +488,20 @@ impl NaiveDateTime {
/// let hmsm = |h, m, s, milli| d.and_hms_milli(h, m, s, milli);
/// assert_eq!(hmsm(3, 5, 7, 980).checked_add_signed(Duration::milliseconds(450)),
/// Some(hmsm(3, 5, 8, 430)));
/// # }
/// ```
///
/// Overflow returns `None`.
///
/// ```
/// # fn main() {
/// # use chrono::{Duration, NaiveDate};
/// # let hms = |h, m, s| NaiveDate::from_ymd(2016, 7, 8).and_hms(h, m, s);
/// assert_eq!(hms(3, 5, 7).checked_add_signed(Duration::days(1_000_000_000)), None);
/// # }
/// ```
///
/// Leap seconds are handled,
/// but the addition assumes that it is the only leap second happened.
///
/// ```
/// # fn main() {
/// # use chrono::{Duration, NaiveDate};
/// # let from_ymd = NaiveDate::from_ymd;
/// # let hmsm = |h, m, s, milli| from_ymd(2016, 7, 8).and_hms_milli(h, m, s, milli);
Expand All @@ -525,7 +520,6 @@ impl NaiveDateTime {
/// Some(hmsm(3, 5, 50, 300)));
/// assert_eq!(leap.checked_add_signed(Duration::days(1)),
/// Some(from_ymd(2016, 7, 9).and_hms_milli(3, 5, 59, 300)));
/// # }
/// ```
pub fn checked_add_signed(self, rhs: OldDuration) -> Option<NaiveDateTime> {
let (time, rhs) = self.time.overflowing_add_signed(rhs);
Expand All @@ -551,7 +545,6 @@ impl NaiveDateTime {
/// # Example
///
/// ```
/// # fn main() {
/// use chrono::{Duration, NaiveDate};
///
/// let from_ymd = NaiveDate::from_ymd;
Expand All @@ -572,24 +565,20 @@ impl NaiveDateTime {
/// let hmsm = |h, m, s, milli| d.and_hms_milli(h, m, s, milli);
/// assert_eq!(hmsm(3, 5, 7, 450).checked_sub_signed(Duration::milliseconds(670)),
/// Some(hmsm(3, 5, 6, 780)));
/// # }
/// ```
///
/// Overflow returns `None`.
///
/// ```
/// # fn main() {
/// # use chrono::{Duration, NaiveDate};
/// # let hms = |h, m, s| NaiveDate::from_ymd(2016, 7, 8).and_hms(h, m, s);
/// assert_eq!(hms(3, 5, 7).checked_sub_signed(Duration::days(1_000_000_000)), None);
/// # }
/// ```
///
/// Leap seconds are handled,
/// but the subtraction assumes that it is the only leap second happened.
///
/// ```
/// # fn main() {
/// # use chrono::{Duration, NaiveDate};
/// # let from_ymd = NaiveDate::from_ymd;
/// # let hmsm = |h, m, s, milli| from_ymd(2016, 7, 8).and_hms_milli(h, m, s, milli);
Expand All @@ -604,7 +593,6 @@ impl NaiveDateTime {
/// Some(hmsm(3, 5, 0, 300)));
/// assert_eq!(leap.checked_sub_signed(Duration::days(1)),
/// Some(from_ymd(2016, 7, 7).and_hms_milli(3, 6, 0, 300)));
/// # }
/// ```
pub fn checked_sub_signed(self, rhs: OldDuration) -> Option<NaiveDateTime> {
let (time, rhs) = self.time.overflowing_sub_signed(rhs);
Expand All @@ -630,7 +618,6 @@ impl NaiveDateTime {
/// # Example
///
/// ```
/// # fn main() {
/// use chrono::{Duration, NaiveDate};
///
/// let from_ymd = NaiveDate::from_ymd;
Expand All @@ -643,22 +630,19 @@ impl NaiveDateTime {
/// let d0 = from_ymd(2016, 1, 1);
/// assert_eq!(d.and_hms_milli(0, 7, 6, 500).signed_duration_since(d0.and_hms(0, 0, 0)),
/// Duration::seconds(189 * 86_400 + 7 * 60 + 6) + Duration::milliseconds(500));
/// # }
/// ```
///
/// Leap seconds are handled, but the subtraction assumes that
/// there were no other leap seconds happened.
///
/// ```
/// # fn main() {
/// # use chrono::{Duration, NaiveDate};
/// # let from_ymd = NaiveDate::from_ymd;
/// let leap = from_ymd(2015, 6, 30).and_hms_milli(23, 59, 59, 1_500);
/// assert_eq!(leap.signed_duration_since(from_ymd(2015, 6, 30).and_hms(23, 0, 0)),
/// Duration::seconds(3600) + Duration::milliseconds(500));
/// assert_eq!(from_ymd(2015, 7, 1).and_hms(1, 0, 0).signed_duration_since(leap),
/// Duration::seconds(3600) - Duration::milliseconds(500));
/// # }
/// ```
pub fn signed_duration_since(self, rhs: NaiveDateTime) -> OldDuration {
self.date.signed_duration_since(rhs.date) + self.time.signed_duration_since(rhs.time)
Expand Down Expand Up @@ -1227,7 +1211,6 @@ impl Timelike for NaiveDateTime {
/// # Example
///
/// ```
/// # fn main() {
/// use chrono::{Duration, NaiveDate};
///
/// let from_ymd = NaiveDate::from_ymd;
Expand All @@ -1245,14 +1228,12 @@ impl Timelike for NaiveDateTime {
///
/// let hmsm = |h, m, s, milli| d.and_hms_milli(h, m, s, milli);
/// assert_eq!(hmsm(3, 5, 7, 980) + Duration::milliseconds(450), hmsm(3, 5, 8, 430));
/// # }
/// ```
///
/// Leap seconds are handled,
/// but the addition assumes that it is the only leap second happened.
///
/// ```
/// # fn main() {
/// # use chrono::{Duration, NaiveDate};
/// # let from_ymd = NaiveDate::from_ymd;
/// # let hmsm = |h, m, s, milli| from_ymd(2016, 7, 8).and_hms_milli(h, m, s, milli);
Expand All @@ -1265,7 +1246,6 @@ impl Timelike for NaiveDateTime {
/// assert_eq!(leap + Duration::seconds(-10), hmsm(3, 5, 50, 300));
/// assert_eq!(leap + Duration::days(1),
/// from_ymd(2016, 7, 9).and_hms_milli(3, 5, 59, 300));
/// # }
/// ```
impl Add<OldDuration> for NaiveDateTime {
type Output = NaiveDateTime;
Expand Down Expand Up @@ -1297,7 +1277,6 @@ impl AddAssign<OldDuration> for NaiveDateTime {
/// # Example
///
/// ```
/// # fn main() {
/// use chrono::{Duration, NaiveDate};
///
/// let from_ymd = NaiveDate::from_ymd;
Expand All @@ -1315,14 +1294,12 @@ impl AddAssign<OldDuration> for NaiveDateTime {
///
/// let hmsm = |h, m, s, milli| d.and_hms_milli(h, m, s, milli);
/// assert_eq!(hmsm(3, 5, 7, 450) - Duration::milliseconds(670), hmsm(3, 5, 6, 780));
/// # }
/// ```
///
/// Leap seconds are handled,
/// but the subtraction assumes that it is the only leap second happened.
///
/// ```
/// # fn main() {
/// # use chrono::{Duration, NaiveDate};
/// # let from_ymd = NaiveDate::from_ymd;
/// # let hmsm = |h, m, s, milli| from_ymd(2016, 7, 8).and_hms_milli(h, m, s, milli);
Expand All @@ -1333,7 +1310,6 @@ impl AddAssign<OldDuration> for NaiveDateTime {
/// assert_eq!(leap - Duration::seconds(60), hmsm(3, 5, 0, 300));
/// assert_eq!(leap - Duration::days(1),
/// from_ymd(2016, 7, 7).and_hms_milli(3, 6, 0, 300));
/// # }
/// ```
impl Sub<OldDuration> for NaiveDateTime {
type Output = NaiveDateTime;
Expand Down Expand Up @@ -1365,7 +1341,6 @@ impl SubAssign<OldDuration> for NaiveDateTime {
/// # Example
///
/// ```
/// # fn main() {
/// use chrono::{Duration, NaiveDate};
///
/// let from_ymd = NaiveDate::from_ymd;
Expand All @@ -1377,22 +1352,19 @@ impl SubAssign<OldDuration> for NaiveDateTime {
/// let d0 = from_ymd(2016, 1, 1);
/// assert_eq!(d.and_hms_milli(0, 7, 6, 500) - d0.and_hms(0, 0, 0),
/// Duration::seconds(189 * 86_400 + 7 * 60 + 6) + Duration::milliseconds(500));
/// # }
/// ```
///
/// Leap seconds are handled, but the subtraction assumes that no other leap
/// seconds happened.
///
/// ```
/// # fn main() {
/// # use chrono::{Duration, NaiveDate};
/// # let from_ymd = NaiveDate::from_ymd;
/// let leap = from_ymd(2015, 6, 30).and_hms_milli(23, 59, 59, 1_500);
/// assert_eq!(leap - from_ymd(2015, 6, 30).and_hms(23, 0, 0),
/// Duration::seconds(3600) + Duration::milliseconds(500));
/// assert_eq!(from_ymd(2015, 7, 1).and_hms(1, 0, 0) - leap,
/// Duration::seconds(3600) - Duration::milliseconds(500));
/// # }
/// ```
impl Sub<NaiveDateTime> for NaiveDateTime {
type Output = OldDuration;
Expand Down

0 comments on commit 0b3a4f5

Please sign in to comment.