Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doctest warnings, remove mention of deprecated methods from main doc #1081

Merged
merged 8 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
/// # Example
///
/// ```
/// use chrono::{Utc, TimeZone, NaiveDate};
/// use chrono::{Utc, NaiveDate};
///
/// let dt = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap().and_hms_milli_opt(0, 0, 1, 444).unwrap().and_local_timezone(Utc).unwrap();
/// assert_eq!(dt.timestamp_millis(), 1_444);
Expand All @@ -232,7 +232,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
/// # Example
///
/// ```
/// use chrono::{Utc, TimeZone, NaiveDate};
/// use chrono::{Utc, NaiveDate};
///
/// let dt = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap().and_hms_micro_opt(0, 0, 1, 444).unwrap().and_local_timezone(Utc).unwrap();
/// assert_eq!(dt.timestamp_micros(), 1_000_444);
Expand All @@ -256,7 +256,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
/// # Example
///
/// ```
/// use chrono::{Utc, TimeZone, NaiveDate};
/// use chrono::{Utc, NaiveDate};
///
/// let dt = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap().and_hms_nano_opt(0, 0, 1, 444).unwrap().and_local_timezone(Utc).unwrap();
/// assert_eq!(dt.timestamp_nanos(), 1_000_000_444);
Expand Down Expand Up @@ -564,7 +564,7 @@ impl DateTime<FixedOffset> {
/// See [RFC 2822 Appendix A.5]
///
/// ```
/// # use chrono::{DateTime, FixedOffset, TimeZone, NaiveDate};
/// # use chrono::{DateTime, FixedOffset, TimeZone};
/// assert_eq!(
/// DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 GMT").unwrap(),
/// FixedOffset::east_opt(0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()
Expand Down Expand Up @@ -640,7 +640,7 @@ impl DateTime<FixedOffset> {
/// # Example
///
/// ```rust
/// # use chrono::{DateTime, FixedOffset, TimeZone, NaiveDate};
/// # use chrono::{DateTime, FixedOffset, TimeZone};
/// let (datetime, remainder) = DateTime::parse_and_remainder(
/// "2015-02-18 23:16:09 +0200 trailing text", "%Y-%m-%d %H:%M:%S %z").unwrap();
/// assert_eq!(
Expand Down Expand Up @@ -695,7 +695,7 @@ where
/// # Examples
///
/// ```rust
/// # use chrono::{DateTime, FixedOffset, SecondsFormat, TimeZone, Utc, NaiveDate};
/// # use chrono::{FixedOffset, SecondsFormat, TimeZone, Utc, NaiveDate};
/// let dt = NaiveDate::from_ymd_opt(2018, 1, 26).unwrap().and_hms_micro_opt(18, 30, 9, 453_829).unwrap().and_local_timezone(Utc).unwrap();
/// assert_eq!(dt.to_rfc3339_opts(SecondsFormat::Millis, false),
/// "2018-01-26T18:30:09.453+00:00");
Expand Down Expand Up @@ -1087,14 +1087,16 @@ where

/// Accepts a relaxed form of RFC3339.
/// A space or a 'T' are acepted as the separator between the date and time
/// parts. Additional spaces are allowed between each component.
/// parts.
///
/// All of these examples are equivalent:
/// ```
/// # use chrono::{DateTime, Utc};
/// "2012-12-12T12:12:12Z".parse::<DateTime<Utc>>();
/// "2012-12-12 12:12:12Z".parse::<DateTime<Utc>>();
/// "2012- 12-12T12: 12:12Z".parse::<DateTime<Utc>>();
/// "2012-12-12T12:12:12Z".parse::<DateTime<Utc>>()?;
/// "2012-12-12 12:12:12Z".parse::<DateTime<Utc>>()?;
/// "2012-12-12 12:12:12+0000".parse::<DateTime<Utc>>()?;
/// "2012-12-12 12:12:12+00:00".parse::<DateTime<Utc>>()?;
/// # Ok::<(), chrono::ParseError>(())
/// ```
impl str::FromStr for DateTime<Utc> {
type Err = ParseError;
Expand All @@ -1106,14 +1108,16 @@ impl str::FromStr for DateTime<Utc> {

/// Accepts a relaxed form of RFC3339.
/// A space or a 'T' are acepted as the separator between the date and time
/// parts. Additional spaces are allowed between each component.
/// parts.
///
/// All of these examples are equivalent:
/// ```
/// # use chrono::{DateTime, Local};
/// "2012-12-12T12:12:12Z".parse::<DateTime<Local>>();
/// "2012-12-12 12:12:12Z".parse::<DateTime<Local>>();
/// "2012- 12-12T12: 12:12Z".parse::<DateTime<Local>>();
/// "2012-12-12T12:12:12Z".parse::<DateTime<Local>>()?;
/// "2012-12-12 12:12:12Z".parse::<DateTime<Local>>()?;
/// "2012-12-12 12:12:12+0000".parse::<DateTime<Local>>()?;
/// "2012-12-12 12:12:12+00:00".parse::<DateTime<Local>>()?;
/// # Ok::<(), chrono::ParseError>(())
/// ```
#[cfg(feature = "clock")]
#[cfg_attr(docsrs, doc(cfg(feature = "clock")))]
Expand Down
61 changes: 34 additions & 27 deletions src/datetime/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<'de> de::Deserialize<'de> for DateTime<Local> {
/// # Example:
///
/// ```rust
/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::{Deserialize, Serialize};
/// use chrono::serde::ts_nanoseconds;
/// #[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -158,7 +158,7 @@ pub mod ts_nanoseconds {
/// # Example:
///
/// ```rust
/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::Serialize;
/// use chrono::serde::ts_nanoseconds::serialize as to_nano_ts;
/// #[derive(Serialize)]
Expand Down Expand Up @@ -189,16 +189,17 @@ pub mod ts_nanoseconds {
/// # Example:
///
/// ```rust
/// # use chrono::{DateTime, Utc};
/// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_nanoseconds::deserialize as from_nano_ts;
/// #[derive(Deserialize)]
/// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_nano_ts")]
/// time: DateTime<Utc>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355733 }"#)?;
/// assert_eq!(my_s, S { time: Utc.timestamp_opt(1526522699, 918355733).unwrap() });
/// # Ok::<(), serde_json::Error>(())
/// ```
#[must_use]
Expand Down Expand Up @@ -247,7 +248,7 @@ pub mod ts_nanoseconds {
/// # Example:
///
/// ```rust
/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::{Deserialize, Serialize};
/// use chrono::serde::ts_nanoseconds_option;
/// #[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -282,7 +283,7 @@ pub mod ts_nanoseconds_option {
/// # Example:
///
/// ```rust
/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::Serialize;
/// use chrono::serde::ts_nanoseconds_option::serialize as to_nano_tsopt;
/// #[derive(Serialize)]
Expand Down Expand Up @@ -316,16 +317,17 @@ pub mod ts_nanoseconds_option {
/// # Example:
///
/// ```rust
/// # use chrono::{DateTime, Utc};
/// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_nanoseconds_option::deserialize as from_nano_tsopt;
/// #[derive(Deserialize)]
/// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_nano_tsopt")]
/// time: Option<DateTime<Utc>>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355733 }"#)?;
/// assert_eq!(my_s, S { time: Utc.timestamp_opt(1526522699, 918355733).single() });
/// # Ok::<(), serde_json::Error>(())
/// ```
#[must_use]
Expand Down Expand Up @@ -378,7 +380,7 @@ pub mod ts_nanoseconds_option {
/// # Example:
///
/// ```rust
/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::{Deserialize, Serialize};
/// use chrono::serde::ts_microseconds;
/// #[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -413,7 +415,7 @@ pub mod ts_microseconds {
/// # Example:
///
/// ```rust
/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::Serialize;
/// use chrono::serde::ts_microseconds::serialize as to_micro_ts;
/// #[derive(Serialize)]
Expand Down Expand Up @@ -444,16 +446,17 @@ pub mod ts_microseconds {
/// # Example:
///
/// ```rust
/// # use chrono::{DateTime, Utc};
/// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_microseconds::deserialize as from_micro_ts;
/// #[derive(Deserialize)]
/// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_micro_ts")]
/// time: DateTime<Utc>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355 }"#)?;
/// assert_eq!(my_s, S { time: Utc.timestamp_opt(1526522699, 918355000).unwrap() });
/// # Ok::<(), serde_json::Error>(())
/// ```
#[must_use]
Expand Down Expand Up @@ -502,7 +505,7 @@ pub mod ts_microseconds {
/// # Example:
///
/// ```rust
/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::{Deserialize, Serialize};
/// use chrono::serde::ts_microseconds_option;
/// #[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -536,7 +539,7 @@ pub mod ts_microseconds_option {
/// # Example:
///
/// ```rust
/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::Serialize;
/// use chrono::serde::ts_microseconds_option::serialize as to_micro_tsopt;
/// #[derive(Serialize)]
Expand Down Expand Up @@ -570,16 +573,17 @@ pub mod ts_microseconds_option {
/// # Example:
///
/// ```rust
/// # use chrono::{DateTime, Utc};
/// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_microseconds_option::deserialize as from_micro_tsopt;
/// #[derive(Deserialize)]
/// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_micro_tsopt")]
/// time: Option<DateTime<Utc>>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355 }"#)?;
/// assert_eq!(my_s, S { time: Utc.timestamp_opt(1526522699, 918355000).single() });
/// # Ok::<(), serde_json::Error>(())
/// ```
#[must_use]
Expand Down Expand Up @@ -632,7 +636,7 @@ pub mod ts_microseconds_option {
/// # Example
///
/// ```rust
/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::{Deserialize, Serialize};
/// use chrono::serde::ts_milliseconds;
/// #[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -667,7 +671,7 @@ pub mod ts_milliseconds {
/// # Example:
///
/// ```rust
/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::Serialize;
/// use chrono::serde::ts_milliseconds::serialize as to_milli_ts;
/// #[derive(Serialize)]
Expand Down Expand Up @@ -698,16 +702,17 @@ pub mod ts_milliseconds {
/// # Example:
///
/// ```rust
/// # use chrono::{DateTime, Utc};
/// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_milliseconds::deserialize as from_milli_ts;
/// #[derive(Deserialize)]
/// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_milli_ts")]
/// time: DateTime<Utc>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918 }"#)?;
/// assert_eq!(my_s, S { time: Utc.timestamp_opt(1526522699, 918000000).unwrap() });
/// # Ok::<(), serde_json::Error>(())
/// ```
#[must_use]
Expand Down Expand Up @@ -753,7 +758,7 @@ pub mod ts_milliseconds {
/// # Example
///
/// ```rust
/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::{Deserialize, Serialize};
/// use chrono::serde::ts_milliseconds_option;
/// #[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -787,7 +792,7 @@ pub mod ts_milliseconds_option {
/// # Example:
///
/// ```rust
/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::Serialize;
/// use chrono::serde::ts_milliseconds_option::serialize as to_milli_tsopt;
/// #[derive(Serialize)]
Expand Down Expand Up @@ -838,7 +843,7 @@ pub mod ts_milliseconds_option {
/// }
///
/// let my_s: E<S> = serde_json::from_str(r#"{ "time": 1526522699918 }"#)?;
/// assert_eq!(my_s, E::V(S { time: Some(Utc.timestamp(1526522699, 918000000)) }));
/// assert_eq!(my_s, E::V(S { time: Some(Utc.timestamp_opt(1526522699, 918000000).unwrap()) }));
/// let s: E<S> = serde_json::from_str(r#"{ "time": null }"#)?;
/// assert_eq!(s, E::V(S { time: None }));
/// let t: E<S> = serde_json::from_str(r#"{}"#)?;
Expand Down Expand Up @@ -962,16 +967,17 @@ pub mod ts_seconds {
/// # Example:
///
/// ```rust
/// # use chrono::{DateTime, Utc};
/// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_seconds::deserialize as from_ts;
/// #[derive(Deserialize)]
/// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_ts")]
/// time: DateTime<Utc>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1431684000 }"#)?;
/// assert_eq!(my_s, S { time: Utc.timestamp_opt(1431684000, 0).unwrap() });
/// # Ok::<(), serde_json::Error>(())
/// ```
#[must_use]
Expand Down Expand Up @@ -1082,16 +1088,17 @@ pub mod ts_seconds_option {
/// # Example:
///
/// ```rust
/// # use chrono::{DateTime, Utc};
/// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_seconds_option::deserialize as from_tsopt;
/// #[derive(Deserialize)]
/// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_tsopt")]
/// time: Option<DateTime<Utc>>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1431684000 }"#)?;
/// assert_eq!(my_s, S { time: Utc.timestamp_opt(1431684000, 0).single() });
/// # Ok::<(), serde_json::Error>(())
/// ```
#[must_use]
Expand Down
3 changes: 1 addition & 2 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
//! # Example
#![cfg_attr(not(feature = "std"), doc = "```ignore")]
#![cfg_attr(feature = "std", doc = "```rust")]
//! # use std::error::Error;
//! use chrono::prelude::*;
//! use chrono::{TimeZone, Utc};
//!
//! let date_time = Utc.with_ymd_and_hms(2020, 11, 10, 0, 1, 32).unwrap();
//!
Expand Down
5 changes: 3 additions & 2 deletions src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,9 @@ where
///
/// ```
/// # use chrono::{DateTime, offset::FixedOffset};
/// "2000-01-02T03:04:05Z".parse::<DateTime<FixedOffset>>();
/// "2000-01-02 03:04:05Z".parse::<DateTime<FixedOffset>>();
/// "2000-01-02T03:04:05Z".parse::<DateTime<FixedOffset>>()?;
/// "2000-01-02 03:04:05Z".parse::<DateTime<FixedOffset>>()?;
/// # Ok::<(), chrono::ParseError>(())
/// ```
impl str::FromStr for DateTime<FixedOffset> {
type Err = ParseError;
Expand Down
Loading