Skip to content

Commit

Permalink
Move SecondsFormat from datetime to format::formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Sep 27, 2023
1 parent 5237de6 commit b7857ba
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
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
34 changes: 32 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,38 @@ 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](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,
}

/// 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
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,13 @@ pub use datetime::rustc_serialize::TsSeconds;
pub use datetime::DateTime;
#[allow(deprecated)]
#[doc(no_inline)]
pub use datetime::{SecondsFormat, MAX_DATETIME, MIN_DATETIME};
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(inline)]
Expand Down

0 comments on commit b7857ba

Please sign in to comment.