Skip to content

Commit 6aec38f

Browse files
mjn298Mike Nissenbaum
andauthored
[3161] Implement Debug for DateTime (#3619)
## Motivation and Context <!--- Why is this change required? What problem does it solve? --> According to #3161 , the Debug output was in a marginally legible format. <!--- If it fixes an open issue, please link to the issue here --> #3161 ## Description <!--- Describe your changes in detail --> 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 <!--- Please describe in detail how you tested your changes --> I added unit tests, and ran `cargo test` within the `rust-runtime` directory. <!--- Include details of your testing environment, and the tests you ran to --> Aarch64 mac terminal - `$ cd rust-runtime && cargo test` <!--- see how your change affects other areas of the code, etc. --> 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 <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [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 <mnissenb@amazon.com>
1 parent 26f1624 commit 6aec38f

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

CHANGELOG.next.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@
99
# message = "Fix typos in module documentation for generated crates"
1010
# references = ["smithy-rs#920"]
1111
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
12-
# author = "rcoh"
12+
# author = "rcoh"
13+
14+
15+
[[smithy-rs]]
16+
message = "Implement Debug for DateTime"
17+
references = ["smithy-rs#3161"]
18+
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "all" }
19+
author = "mnissenb"

rust-runtime/aws-smithy-types/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "aws-smithy-types"
3-
version = "1.1.8"
3+
version = "1.1.9"
44
authors = [
55
"AWS Rust SDK Team <aws-sdk-rust@amazon.com>",
66
"Russell Cohen <rcoh@amazon.com>",

rust-runtime/aws-smithy-types/src/date_time/mod.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const NANOS_PER_SECOND_U32: u32 = 1_000_000_000;
5555
/// The [`aws-smithy-types-convert`](https://crates.io/crates/aws-smithy-types-convert) crate
5656
/// can be used for conversions to/from other libraries, such as
5757
/// [`time`](https://crates.io/crates/time) or [`chrono`](https://crates.io/crates/chrono).
58-
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
58+
#[derive(PartialEq, Eq, Hash, Clone, Copy)]
5959
pub struct DateTime {
6060
pub(crate) seconds: i64,
6161
/// Subsecond nanos always advances the wallclock time, even for times where seconds is negative
@@ -336,6 +336,12 @@ impl Display for DateTime {
336336
write!(f, "{}", date)
337337
}
338338
}
339+
340+
impl fmt::Debug for DateTime {
341+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
342+
fmt::Display::fmt(self, f)
343+
}
344+
}
339345
/// Failure to convert a `DateTime` to or from another type.
340346
#[derive(Debug)]
341347
#[non_exhaustive]
@@ -394,6 +400,21 @@ mod test {
394400
assert_eq!(format!("{}", date_time), "1970-07-16T16:52:03Z");
395401
}
396402

403+
#[test]
404+
fn test_debug_date_time() {
405+
let date_time = DateTime::from_secs(1576540098);
406+
assert_eq!(format!("{:?}", date_time), "2019-12-16T23:48:18Z");
407+
408+
let date_time = DateTime::from_fractional_secs(1576540098, 0.52);
409+
assert_eq!(format!("{:?}", date_time), "2019-12-16T23:48:18.52Z");
410+
411+
let date_time = DateTime::from_secs(1699942527);
412+
assert_eq!(format!("{:?}", date_time), "2023-11-14T06:15:27Z");
413+
414+
let date_time = DateTime::from_secs(16995123);
415+
assert_eq!(format!("{:?}", date_time), "1970-07-16T16:52:03Z");
416+
}
417+
397418
#[test]
398419
fn test_fmt() {
399420
let date_time = DateTime::from_secs(1576540098);

0 commit comments

Comments
 (0)