diff --git a/src/date.rs b/src/date.rs index 0d96976cb..263468e7b 100644 --- a/src/date.rs +++ b/src/date.rs @@ -41,15 +41,6 @@ pub struct Date { value: i32, } -impl fmt::Debug for Date { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - f.debug_struct("Date") - .field("year", &self.year()) - .field("ordinal", &self.ordinal()) - .finish() - } -} - impl Date { /// The minimum valid `Date`. /// @@ -983,6 +974,12 @@ impl fmt::Display for Date { } } } + +impl fmt::Debug for Date { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + fmt::Display::fmt(self, f) + } +} // endregion formatting & parsing // region: trait impls diff --git a/src/offset_date_time.rs b/src/offset_date_time.rs index 598203a8a..ad68fc111 100644 --- a/src/offset_date_time.rs +++ b/src/offset_date_time.rs @@ -27,7 +27,7 @@ const UNIX_EPOCH_JULIAN_DAY: i32 = Date::__from_ordinal_date_unchecked(1970, 1). /// A [`PrimitiveDateTime`] with a [`UtcOffset`]. /// /// All comparisons are performed using the UTC time. -#[derive(Debug, Clone, Copy, Eq)] +#[derive(Clone, Copy, Eq)] pub struct OffsetDateTime { /// The [`PrimitiveDateTime`], which is _always_ in the stored offset. pub(crate) local_datetime: PrimitiveDateTime, @@ -1132,6 +1132,12 @@ impl fmt::Display for OffsetDateTime { write!(f, "{} {} {}", self.date(), self.time(), self.offset) } } + +impl fmt::Debug for OffsetDateTime { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self, f) + } +} // endregion formatting & parsing // region: trait impls diff --git a/src/primitive_date_time.rs b/src/primitive_date_time.rs index 798d089dd..5ea54c3b5 100644 --- a/src/primitive_date_time.rs +++ b/src/primitive_date_time.rs @@ -13,7 +13,7 @@ use crate::parsing::Parsable; use crate::{error, util, Date, Duration, Month, OffsetDateTime, Time, UtcOffset, Weekday}; /// Combined date and time. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct PrimitiveDateTime { #[allow(clippy::missing_docs_in_private_items)] pub(crate) date: Date, @@ -821,6 +821,12 @@ impl fmt::Display for PrimitiveDateTime { write!(f, "{} {}", self.date, self.time) } } + +impl fmt::Debug for PrimitiveDateTime { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self, f) + } +} // endregion formatting & parsing // region: trait impls diff --git a/src/time.rs b/src/time.rs index aae1f2ae5..b0a918e49 100644 --- a/src/time.rs +++ b/src/time.rs @@ -42,17 +42,6 @@ pub struct Time { padding: Padding, } -impl fmt::Debug for Time { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Time") - .field("hour", &self.hour) - .field("minute", &self.minute) - .field("second", &self.second) - .field("nanosecond", &self.nanosecond) - .finish() - } -} - impl Time { /// Create a `Time` that is exactly midnight. /// @@ -656,6 +645,12 @@ impl fmt::Display for Time { ) } } + +impl fmt::Debug for Time { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self, f) + } +} // endregion formatting & parsing // region: trait impls diff --git a/src/utc_offset.rs b/src/utc_offset.rs index 5f3b72f9b..73384e762 100644 --- a/src/utc_offset.rs +++ b/src/utc_offset.rs @@ -20,7 +20,7 @@ use crate::OffsetDateTime; /// This struct can store values up to ±23:59:59. If you need support outside this range, please /// file an issue with your use case. // All three components _must_ have the same sign. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct UtcOffset { #[allow(clippy::missing_docs_in_private_items)] hours: i8, @@ -326,6 +326,12 @@ impl fmt::Display for UtcOffset { ) } } + +impl fmt::Debug for UtcOffset { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self, f) + } +} // endregion formatting & parsing impl Neg for UtcOffset { diff --git a/tests/integration/date.rs b/tests/integration/date.rs index b1cd3289c..ed564fadc 100644 --- a/tests/integration/date.rs +++ b/tests/integration/date.rs @@ -8,10 +8,7 @@ use time::{util, Date, Duration, Month, Weekday}; #[test] fn debug() { - assert_eq!( - format!("{:?}", date!(2020 - 02 - 03)), - "Date { year: 2020, ordinal: 34 }" - ); + assert_eq!(format!("{:?}", date!(2020 - 02 - 03)), "2020-02-03"); } #[test]