Skip to content

Commit

Permalink
Fix behavior of datetime formatting (#3790)
Browse files Browse the repository at this point in the history
  • Loading branch information
landonxjames authored Aug 15, 2024
2 parents f4e3b40 + 9577479 commit 83ef515
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
34 changes: 17 additions & 17 deletions rust-runtime/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-smithy-types"
version = "1.2.1"
version = "1.2.2"
authors = [
"AWS Rust SDK Team <aws-sdk-rust@amazon.com>",
"Russell Cohen <rcoh@amazon.com>",
Expand Down
14 changes: 13 additions & 1 deletion rust-runtime/aws-smithy-types/src/date_time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,12 @@ impl Ord for DateTime {

impl Display for DateTime {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let date = self.fmt(Format::DateTime).map_err(|_| fmt::Error)?;
// Some dates are out of range to be serialized with `DateTime`.
// In these cases, fallback to using epoch seconds which always works
let date = match self.fmt(Format::DateTime) {
Ok(date) => date,
Err(_err) => format::epoch_seconds::format(self),
};
write!(f, "{}", date)
}
}
Expand Down Expand Up @@ -629,6 +634,13 @@ mod test {
);
}

#[test]
fn formatting_of_early_dates() {
let date: DateTime =
DateTime::from_str("Mon, 16 Dec -019 23:48:18 GMT", Format::HttpDate).unwrap();
assert_eq!(format!("{}", date), "-62736509502");
}

#[test]
fn ord() {
let first = DateTime::from_secs_and_nanos(-1, 0);
Expand Down

0 comments on commit 83ef515

Please sign in to comment.