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

Documentation tweaks #1274

Merged
merged 7 commits into from
Sep 27, 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
34 changes: 1 addition & 33 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::format::{
StrftimeItems, TOO_LONG,
};
#[cfg(feature = "alloc")]
use crate::format::{write_rfc2822, write_rfc3339, DelayedFormat};
use crate::format::{write_rfc2822, write_rfc3339, DelayedFormat, SecondsFormat};
use crate::naive::{Days, IsoWeek, NaiveDate, NaiveDateTime, NaiveTime};
#[cfg(feature = "clock")]
use crate::offset::Local;
Expand All @@ -44,38 +44,6 @@ pub(super) mod serde;
#[cfg(test)]
mod tests;

/// Specific formatting options for seconds. This may be extended in the
/// future, so exhaustive matching in external code is not recommended.
///
/// See the `TimeZone::to_rfc3339_opts` function for usage.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[allow(clippy::manual_non_exhaustive)]
pub enum SecondsFormat {
/// Format whole seconds only, with no decimal point nor subseconds.
Secs,

/// Use fixed 3 subsecond digits. This corresponds to
/// [Fixed::Nanosecond3](format/enum.Fixed.html#variant.Nanosecond3).
Millis,

/// Use fixed 6 subsecond digits. This corresponds to
/// [Fixed::Nanosecond6](format/enum.Fixed.html#variant.Nanosecond6).
Micros,

/// Use fixed 9 subsecond digits. This corresponds to
/// [Fixed::Nanosecond9](format/enum.Fixed.html#variant.Nanosecond9).
Nanos,

/// Automatically select one of `Secs`, `Millis`, `Micros`, or `Nanos` to
/// display all available non-zero sub-second digits. This corresponds to
/// [Fixed::Nanosecond](format/enum.Fixed.html#variant.Nanosecond).
AutoSi,

// Do not match against this.
#[doc(hidden)]
__NonExhaustive,
}

/// ISO 8601 combined date and time with time zone.
///
/// There are some constructors implemented here (the `from_*` methods), but
Expand Down
3 changes: 2 additions & 1 deletion src/datetime/rustc_serialize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{DateTime, SecondsFormat};
use super::DateTime;
use crate::format::SecondsFormat;
#[cfg(feature = "clock")]
use crate::offset::Local;
use crate::offset::{FixedOffset, LocalResult, TimeZone, Utc};
Expand Down
4 changes: 2 additions & 2 deletions src/datetime/serde.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use core::fmt;
use serde::{de, ser};

use super::{DateTime, SecondsFormat};
use crate::format::write_rfc3339;
use super::DateTime;
use crate::format::{write_rfc3339, SecondsFormat};
use crate::naive::datetime::serde::serde_from;
#[cfg(feature = "clock")]
use crate::offset::Local;
Expand Down
30 changes: 28 additions & 2 deletions src/format/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use core::borrow::Borrow;
use core::fmt::Display;
use core::fmt::{self, Write};

#[cfg(any(feature = "alloc", feature = "serde", feature = "rustc-serialize"))]
use crate::datetime::SecondsFormat;
#[cfg(feature = "alloc")]
use crate::offset::Offset;
#[cfg(any(feature = "alloc", feature = "serde", feature = "rustc-serialize"))]
Expand Down Expand Up @@ -504,6 +502,34 @@ impl OffsetFormat {
}
}

/// Specific formatting options for seconds. This may be extended in the
/// future, so exhaustive matching in external code is not recommended.
///
/// See the `TimeZone::to_rfc3339_opts` function for usage.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[allow(clippy::manual_non_exhaustive)]
pub enum SecondsFormat {
/// Format whole seconds only, with no decimal point nor subseconds.
Secs,

/// Use fixed 3 subsecond digits. This corresponds to [Fixed::Nanosecond3].
Millis,

/// Use fixed 6 subsecond digits. This corresponds to [Fixed::Nanosecond6].
Micros,

/// Use fixed 9 subsecond digits. This corresponds to [Fixed::Nanosecond9].
Nanos,

/// Automatically select one of `Secs`, `Millis`, `Micros`, or `Nanos` to display all available
/// non-zero sub-second digits. This corresponds to [Fixed::Nanosecond].
AutoSi,

// Do not match against this.
#[doc(hidden)]
__NonExhaustive,
}

/// Writes the date, time and offset to the string. same as `%Y-%m-%dT%H:%M:%S%.f%:z`
#[inline]
#[cfg(any(feature = "alloc", feature = "serde", feature = "rustc-serialize"))]
Expand Down
1 change: 1 addition & 0 deletions src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub(crate) use formatting::write_hundreds;
pub(crate) use formatting::write_rfc2822;
#[cfg(any(feature = "alloc", feature = "serde", feature = "rustc-serialize"))]
pub(crate) use formatting::write_rfc3339;
pub use formatting::SecondsFormat;
#[cfg(feature = "alloc")]
#[allow(deprecated)]
pub use formatting::{format, format_item, DelayedFormat};
Expand Down
45 changes: 25 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,70 +477,73 @@ extern crate alloc;
mod duration;
pub use duration::Duration;
#[cfg(feature = "std")]
#[doc(no_inline)]
pub use duration::OutOfRangeError;

use core::fmt;

/// A convenience module appropriate for glob imports (`use chrono::prelude::*;`).
pub mod prelude {
#[doc(no_inline)]
#[allow(deprecated)]
pub use crate::Date;
#[cfg(feature = "clock")]
#[doc(no_inline)]
pub use crate::Local;
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
#[doc(no_inline)]
pub use crate::Locale;
#[doc(no_inline)]
pub use crate::SubsecRound;
#[doc(no_inline)]
pub use crate::{DateTime, SecondsFormat};
#[doc(no_inline)]
pub use crate::{Datelike, Month, Timelike, Weekday};
#[doc(no_inline)]
pub use crate::{FixedOffset, Utc};
#[doc(no_inline)]
pub use crate::{NaiveDate, NaiveDateTime, NaiveTime};
#[doc(no_inline)]
pub use crate::{Offset, TimeZone};
}

mod date;
#[allow(deprecated)]
pub use date::{Date, MAX_DATE, MIN_DATE};
pub use date::Date;
#[doc(no_inline)]
#[allow(deprecated)]
pub use date::{MAX_DATE, MIN_DATE};

mod datetime;
#[cfg(feature = "rustc-serialize")]
pub use datetime::rustc_serialize::TsSeconds;
pub use datetime::DateTime;
#[allow(deprecated)]
pub use datetime::{DateTime, SecondsFormat, MAX_DATETIME, MIN_DATETIME};
#[doc(no_inline)]
pub use datetime::{MAX_DATETIME, MIN_DATETIME};

pub mod format;
/// L10n locales.
#[cfg(feature = "unstable-locales")]
pub use format::Locale;
pub use format::{ParseError, ParseResult};
pub use format::{ParseError, ParseResult, SecondsFormat};

pub mod naive;
#[doc(no_inline)]
pub use naive::{Days, IsoWeek, NaiveDate, NaiveDateTime, NaiveTime, NaiveWeek};
#[doc(inline)]
pub use naive::{Days, NaiveDate, NaiveDateTime, NaiveTime};
pub use naive::{IsoWeek, NaiveWeek};

pub mod offset;
#[cfg(feature = "clock")]
#[doc(no_inline)]
#[doc(inline)]
pub use offset::Local;
#[doc(no_inline)]
pub use offset::{FixedOffset, LocalResult, Offset, TimeZone, Utc};
pub use offset::LocalResult;
#[doc(inline)]
pub use offset::{FixedOffset, Offset, TimeZone, Utc};

mod round;
pub mod round;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the argument put forth in the commit message. What's the rationale for this change?

Copy link
Collaborator Author

@pitdicker pitdicker Sep 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to highlight the importants traits in the "Traits" section: TimeZone, Offset, Datelike and Timelike.
I don't think DurationRound and SubsecRound are good enough to be part of the list in the main documentation.
We can only hide it in the list if the round module is public.

To say it stronger, in my opinion the DurationRound trait is something that begs for a replacement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, sure, but if that's the goal IMO the other changes to that goal should be in the same commit as that. In general, the first commit here seems too large/unfocused (it probably doesn't help that I'm completely unfamiliar with the semantics of doc(no_inline))...

Copy link
Collaborator Author

@pitdicker pitdicker Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O, sorry. That was only the goal of that commit. No: the goal of the PR was tweaking doc(inline) and doc(no_inline).

If the original module is public:

  • a re-export comes under the list "Re-exports".
  • doc(inline) on a re-export copies the documentation, so it now lives at two places.

If the original module is private:

  • a re-export moves the documentation.
  • doc(no_inline) makes the documentation unreachable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, the first commit here seems too large/unfocused

I have split it up into three commits.

pub use round::{DurationRound, RoundingError, SubsecRound};

mod weekday;
pub use weekday::{ParseWeekdayError, Weekday};
#[doc(no_inline)]
pub use weekday::ParseWeekdayError;
pub use weekday::Weekday;

mod month;
pub use month::{Month, Months, ParseMonthError};
#[doc(no_inline)]
pub use month::ParseMonthError;
pub use month::{Month, Months};

mod traits;
pub use traits::{Datelike, Timelike};
Expand Down Expand Up @@ -611,6 +614,7 @@ impl std::error::Error for OutOfRange {}

/// Workaround because `?` is not (yet) available in const context.
#[macro_export]
#[doc(hidden)]
macro_rules! try_opt {
($e:expr) => {
match $e {
Expand All @@ -622,6 +626,7 @@ macro_rules! try_opt {

/// Workaround because `.expect()` is not (yet) available in const context.
#[macro_export]
#[doc(hidden)]
macro_rules! expect {
($e:expr, $m:literal) => {
match $e {
Expand Down
26 changes: 12 additions & 14 deletions src/naive/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ impl NaiveWeek {
}

/// Returns a [`RangeInclusive<T>`] representing the whole week bounded by
/// [first_day](./struct.NaiveWeek.html#method.first_day) and
/// [last_day](./struct.NaiveWeek.html#method.last_day) functions.
/// [first_day](NaiveWeek::first_day) and [last_day](NaiveWeek::last_day) functions.
///
/// # Panics
///
Expand Down Expand Up @@ -160,12 +159,12 @@ impl Days {
///
/// * 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 [`Datelike::year_ce`](../trait.Datelike.html#method.year_ce) method.
/// use the [`Datelike::year_ce`] method.
///
/// # Week Date
///
/// The ISO 8601 **week date** is a triple of year number, week number
/// and [day of the week](../enum.Weekday.html) with the following rules:
/// and [day of the week](Weekday) with the following rules:
///
/// * 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.
Expand All @@ -176,10 +175,9 @@ impl Days {
/// * The year number in the week date may *not* correspond to the actual Gregorian year.
/// For example, January 3, 2016 (Sunday) was on the last (53rd) week of 2015.
///
/// Chrono's date types default to the ISO 8601 [calendar date](#calendar-date),
/// but [`Datelike::iso_week`](../trait.Datelike.html#tymethod.iso_week) and
/// [`Datelike::weekday`](../trait.Datelike.html#tymethod.weekday) methods
/// can be used to get the corresponding week date.
/// Chrono's date types default to the ISO 8601 [calendar date](#calendar-date), but
/// [`Datelike::iso_week`] and [`Datelike::weekday`] methods can be used to get the corresponding
/// week date.
///
/// # Ordinal Date
///
Expand Down Expand Up @@ -542,7 +540,7 @@ impl NaiveDate {
}

/// Parses a string with the specified format string and returns a new `NaiveDate`.
/// See the [`format::strftime` module](../format/strftime/index.html)
/// See the [`format::strftime` module](crate::format::strftime)
/// on the supported escape sequences.
///
/// # Example
Expand Down Expand Up @@ -591,7 +589,7 @@ impl NaiveDate {

/// Parses a string from a user-specified format into a new `NaiveDate` value, and a slice with
/// the remaining portion of the string.
/// See the [`format::strftime` module](../format/strftime/index.html)
/// See the [`format::strftime` module](crate::format::strftime)
/// on the supported escape sequences.
///
/// Similar to [`parse_from_str`](#method.parse_from_str).
Expand Down Expand Up @@ -1280,7 +1278,7 @@ impl NaiveDate {
}

/// Formats the date with the specified format string.
/// See the [`format::strftime` module](../format/strftime/index.html)
/// See the [`format::strftime` module](crate::format::strftime)
/// on the supported escape sequences.
///
/// This returns a `DelayedFormat`,
Expand Down Expand Up @@ -2139,7 +2137,7 @@ impl DoubleEndedIterator for NaiveDateWeeksIterator {
impl FusedIterator for NaiveDateWeeksIterator {}

/// The `Debug` output of the naive date `d` is the same as
/// [`d.format("%Y-%m-%d")`](../format/strftime/index.html).
/// [`d.format("%Y-%m-%d")`](crate::format::strftime).
///
/// The string printed can be readily parsed via the `parse` method on `str`.
///
Expand Down Expand Up @@ -2182,7 +2180,7 @@ impl fmt::Debug for NaiveDate {
}

/// The `Display` output of the naive date `d` is the same as
/// [`d.format("%Y-%m-%d")`](../format/strftime/index.html).
/// [`d.format("%Y-%m-%d")`](crate::format::strftime).
///
/// The string printed can be readily parsed via the `parse` method on `str`.
///
Expand Down Expand Up @@ -2210,7 +2208,7 @@ impl fmt::Display for NaiveDate {
}

/// Parsing a `str` into a `NaiveDate` uses the same format,
/// [`%Y-%m-%d`](../format/strftime/index.html), as in `Debug` and `Display`.
/// [`%Y-%m-%d`](crate::format::strftime), as in `Debug` and `Display`.
///
/// # Example
///
Expand Down
Loading