From 6aec38f119e04d1d4900c13625a5f1b523af94f8 Mon Sep 17 00:00:00 2001 From: Mike N Date: Wed, 1 May 2024 18:19:17 -0400 Subject: [PATCH] [3161] Implement Debug for DateTime (#3619) ## Motivation and Context According to #3161 , the Debug output was in a marginally legible format. #3161 ## Description Since there's no expected difference between `Debug` and `Display` for date_time, the `fmt::Debug` for `date_time` calls the already implemented `Display`. ## Testing I added unit tests, and ran `cargo test` within the `rust-runtime` directory. Aarch64 mac terminal - `$ cd rust-runtime && cargo test` A single test failed: `client::waiters::backoff::tests::backoff_with_seeded_jitter` at first. After rebasing on upstream, the failure went away. Thanks for the fix. ## Checklist - [X] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --------- Co-authored-by: Mike Nissenbaum --- CHANGELOG.next.toml | 9 +++++++- rust-runtime/aws-smithy-types/Cargo.toml | 2 +- .../aws-smithy-types/src/date_time/mod.rs | 23 ++++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index fc4c4c2578..029f25c346 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -9,4 +9,11 @@ # message = "Fix typos in module documentation for generated crates" # references = ["smithy-rs#920"] # meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"} -# author = "rcoh" \ No newline at end of file +# author = "rcoh" + + +[[smithy-rs]] +message = "Implement Debug for DateTime" +references = ["smithy-rs#3161"] +meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "all" } +author = "mnissenb" diff --git a/rust-runtime/aws-smithy-types/Cargo.toml b/rust-runtime/aws-smithy-types/Cargo.toml index 0b30a2e428..c16bf6615a 100644 --- a/rust-runtime/aws-smithy-types/Cargo.toml +++ b/rust-runtime/aws-smithy-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-smithy-types" -version = "1.1.8" +version = "1.1.9" authors = [ "AWS Rust SDK Team ", "Russell Cohen ", diff --git a/rust-runtime/aws-smithy-types/src/date_time/mod.rs b/rust-runtime/aws-smithy-types/src/date_time/mod.rs index bfcbfb22e3..d8b5f7637d 100644 --- a/rust-runtime/aws-smithy-types/src/date_time/mod.rs +++ b/rust-runtime/aws-smithy-types/src/date_time/mod.rs @@ -55,7 +55,7 @@ const NANOS_PER_SECOND_U32: u32 = 1_000_000_000; /// The [`aws-smithy-types-convert`](https://crates.io/crates/aws-smithy-types-convert) crate /// can be used for conversions to/from other libraries, such as /// [`time`](https://crates.io/crates/time) or [`chrono`](https://crates.io/crates/chrono). -#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] +#[derive(PartialEq, Eq, Hash, Clone, Copy)] pub struct DateTime { pub(crate) seconds: i64, /// Subsecond nanos always advances the wallclock time, even for times where seconds is negative @@ -336,6 +336,12 @@ impl Display for DateTime { write!(f, "{}", date) } } + +impl fmt::Debug for DateTime { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self, f) + } +} /// Failure to convert a `DateTime` to or from another type. #[derive(Debug)] #[non_exhaustive] @@ -394,6 +400,21 @@ mod test { assert_eq!(format!("{}", date_time), "1970-07-16T16:52:03Z"); } + #[test] + fn test_debug_date_time() { + let date_time = DateTime::from_secs(1576540098); + assert_eq!(format!("{:?}", date_time), "2019-12-16T23:48:18Z"); + + let date_time = DateTime::from_fractional_secs(1576540098, 0.52); + assert_eq!(format!("{:?}", date_time), "2019-12-16T23:48:18.52Z"); + + let date_time = DateTime::from_secs(1699942527); + assert_eq!(format!("{:?}", date_time), "2023-11-14T06:15:27Z"); + + let date_time = DateTime::from_secs(16995123); + assert_eq!(format!("{:?}", date_time), "1970-07-16T16:52:03Z"); + } + #[test] fn test_fmt() { let date_time = DateTime::from_secs(1576540098);