Skip to content

Commit

Permalink
Rustfmt doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Mar 22, 2024
1 parent c281ce7 commit 3317fd1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 51 deletions.
13 changes: 3 additions & 10 deletions src/datetime/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,8 @@ pub mod ts_microseconds_option {
/// time: DateTime<Utc>,
/// }
///
/// let time = NaiveDate::from_ymd(2018, 5, 17)
/// .unwrap()
/// .and_hms_milli(02, 04, 59, 918)
/// .unwrap()
/// .and_utc();
/// let time =
/// NaiveDate::from_ymd(2018, 5, 17).unwrap().and_hms_milli(02, 04, 59, 918).unwrap().and_utc();
/// let my_s = S { time: time.clone() };
///
/// let as_string = serde_json::to_string(&my_s)?;
Expand Down Expand Up @@ -813,11 +810,7 @@ pub mod ts_milliseconds {
/// }
///
/// let time = Some(
/// NaiveDate::from_ymd(2018, 5, 17)
/// .unwrap()
/// .and_hms_milli(02, 04, 59, 918)
/// .unwrap()
/// .and_utc(),
/// NaiveDate::from_ymd(2018, 5, 17).unwrap().and_hms_milli(02, 04, 59, 918).unwrap().and_utc(),
/// );
/// let my_s = S { time: time.clone() };
///
Expand Down
6 changes: 2 additions & 4 deletions src/format/strftime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,8 @@ impl<'a> StrftimeItems<'a> {
/// use chrono::format::{Locale, StrftimeItems};
/// use chrono::{FixedOffset, TimeZone};
///
/// let dt = FixedOffset::east(9 * 60 * 60)
/// .unwrap()
/// .with_ymd_and_hms(2023, 7, 11, 0, 34, 59)
/// .unwrap();
/// let dt =
/// FixedOffset::east(9 * 60 * 60).unwrap().with_ymd_and_hms(2023, 7, 11, 0, 34, 59).unwrap();
///
/// // Note: you usually want to combine `StrftimeItems::new_with_locale` with other
/// // locale-aware methods such as `DateTime::format_localized_with_items`.
Expand Down
13 changes: 5 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@
//! assert_eq!(dt.timezone(), FixedOffset::east(9 * 3600)?);
//! assert_eq!(
//! dt.with_timezone(&Utc),
//! NaiveDate::from_ymd(2014, 11, 28)?
//! .and_hms_nano(12, 45, 59, 324310806)?
//! .and_utc()
//! NaiveDate::from_ymd(2014, 11, 28)?.and_hms_nano(12, 45, 59, 324310806)?.and_utc()
//! );
//!
//! // a sample of property manipulations (validates dynamically)
Expand All @@ -221,15 +219,14 @@
//! assert_eq!(dt1.signed_duration_since(dt2), TimeDelta::seconds(-2 * 3600 + 2));
//! assert_eq!(dt2.signed_duration_since(dt1), TimeDelta::seconds(2 * 3600 - 2));
//! assert_eq!(
//! Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap()
//! + TimeDelta::seconds(1_000_000_000),
//! Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap() + TimeDelta::seconds(1_000_000_000),
//! Utc.with_ymd_and_hms(2001, 9, 9, 1, 46, 40).unwrap()
//! );
//! assert_eq!(
//! Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap()
//! - TimeDelta::seconds(1_000_000_000),
//! Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap() - TimeDelta::seconds(1_000_000_000),
//! Utc.with_ymd_and_hms(1938, 4, 24, 22, 13, 20).unwrap()
//! );
//! # Ok::<(), chrono::Error>(())
//! ```
//!
//! ### Formatting and Parsing
Expand Down Expand Up @@ -308,7 +305,7 @@
//! use chrono::prelude::*;
//!
//! let dt = Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap();
//! let fixed_dt = dt.with_timezone(&FixedOffset::east(9*3600).unwrap());
//! let fixed_dt = dt.with_timezone(&FixedOffset::east(9 * 3600).unwrap());
//!
//! // method 1
//! assert_eq!("2014-11-28T12:00:09Z".parse::<DateTime<Utc>>(), Ok(dt.clone()));
Expand Down
2 changes: 1 addition & 1 deletion src/naive/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ impl NaiveDateTime {
self.date
.signed_duration_since(rhs.date)
.checked_add(self.time.signed_duration_since(rhs.time)),
"always in range"
"always in range",
)
}

Expand Down
12 changes: 4 additions & 8 deletions src/offset/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ impl FixedOffset {
/// # #[cfg(feature = "alloc")] {
/// use chrono::{FixedOffset, TimeZone};
/// let hour = 3600;
/// let datetime = FixedOffset::east(5 * hour)
/// .unwrap()
/// .with_ymd_and_hms(2016, 11, 08, 0, 0, 0)
/// .unwrap();
/// let datetime =
/// FixedOffset::east(5 * hour).unwrap().with_ymd_and_hms(2016, 11, 08, 0, 0, 0).unwrap();
/// assert_eq!(&datetime.to_rfc3339(), "2016-11-08T00:00:00+05:00")
/// # }
/// ```
Expand All @@ -72,10 +70,8 @@ impl FixedOffset {
/// # #[cfg(feature = "alloc")] {
/// use chrono::{FixedOffset, TimeZone};
/// let hour = 3600;
/// let datetime = FixedOffset::west(5 * hour)
/// .unwrap()
/// .with_ymd_and_hms(2016, 11, 08, 0, 0, 0)
/// .unwrap();
/// let datetime =
/// FixedOffset::west(5 * hour).unwrap().with_ymd_and_hms(2016, 11, 08, 0, 0, 0).unwrap();
/// assert_eq!(&datetime.to_rfc3339(), "2016-11-08T00:00:00-05:00")
/// # }
/// ```
Expand Down
28 changes: 8 additions & 20 deletions src/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ pub trait SubsecRound {
/// # Example
/// ``` rust
/// # use chrono::{SubsecRound, Timelike, NaiveDate};
/// let dt = NaiveDate::from_ymd(2018, 1, 11)
/// .unwrap()
/// .and_hms_milli(12, 0, 0, 154)
/// .unwrap()
/// .and_utc();
/// let dt =
/// NaiveDate::from_ymd(2018, 1, 11).unwrap().and_hms_milli(12, 0, 0, 154).unwrap().and_utc();
/// assert_eq!(dt.round_subsecs(2).nanosecond(), 150_000_000);
/// assert_eq!(dt.round_subsecs(1).nanosecond(), 200_000_000);
/// ```
Expand All @@ -38,11 +35,8 @@ pub trait SubsecRound {
/// # Example
/// ``` rust
/// # use chrono::{SubsecRound, Timelike, NaiveDate};
/// let dt = NaiveDate::from_ymd(2018, 1, 11)
/// .unwrap()
/// .and_hms_milli(12, 0, 0, 154)
/// .unwrap()
/// .and_utc();
/// let dt =
/// NaiveDate::from_ymd(2018, 1, 11).unwrap().and_hms_milli(12, 0, 0, 154).unwrap().and_utc();
/// assert_eq!(dt.trunc_subsecs(2).nanosecond(), 150_000_000);
/// assert_eq!(dt.trunc_subsecs(1).nanosecond(), 100_000_000);
/// ```
Expand Down Expand Up @@ -117,11 +111,8 @@ pub trait DurationRound: Sized {
/// # Example
/// ``` rust
/// # use chrono::{DurationRound, TimeDelta, NaiveDate};
/// let dt = NaiveDate::from_ymd(2018, 1, 11)
/// .unwrap()
/// .and_hms_milli(12, 0, 0, 154)
/// .unwrap()
/// .and_utc();
/// let dt =
/// NaiveDate::from_ymd(2018, 1, 11).unwrap().and_hms_milli(12, 0, 0, 154).unwrap().and_utc();
/// assert_eq!(
/// dt.duration_round(TimeDelta::milliseconds(10).unwrap()).unwrap().to_string(),
/// "2018-01-11 12:00:00.150 UTC"
Expand All @@ -138,11 +129,8 @@ pub trait DurationRound: Sized {
/// # Example
/// ``` rust
/// # use chrono::{DurationRound, TimeDelta, NaiveDate};
/// let dt = NaiveDate::from_ymd(2018, 1, 11)
/// .unwrap()
/// .and_hms_milli(12, 0, 0, 154)
/// .unwrap()
/// .and_utc();
/// let dt =
/// NaiveDate::from_ymd(2018, 1, 11).unwrap().and_hms_milli(12, 0, 0, 154).unwrap().and_utc();
/// assert_eq!(
/// dt.duration_trunc(TimeDelta::milliseconds(10).unwrap()).unwrap().to_string(),
/// "2018-01-11 12:00:00.150 UTC"
Expand Down

0 comments on commit 3317fd1

Please sign in to comment.