Skip to content

Commit

Permalink
Fix error
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ahmed <[email protected]>
  • Loading branch information
82marbag authored and Daniele Ahmed committed Nov 14, 2022
1 parent 898640b commit 3a99595
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions rust-runtime/aws-smithy-types-convert/src/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,18 @@ pub trait DateTimeExt {
impl DateTimeExt for DateTime {
#[cfg(feature = "convert-chrono")]
fn to_chrono_utc(&self) -> Result<chrono::DateTime<chrono::Utc>, Error> {
Ok(chrono::DateTime::<chrono::Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(self.secs(), self.subsec_nanos())
.ok_or_else(|| {
Error::OutOfRange(Box::new(format!(
"Out-of-range seconds {} or invalid nanoseconds {}",
self.secs(),
self.subsec_nanos()
)))
})?,
chrono::Utc,
))
match chrono::NaiveDateTime::from_timestamp_opt(self.secs(), self.subsec_nanos()) {
None => {
let err: Box<dyn StdError + Send + Sync + 'static> = format!(
"Out-of-range seconds {} or invalid nanoseconds {}",
self.secs(),
self.subsec_nanos()
)
.into();
Err(Error::OutOfRange(err))
}
Some(dt) => Ok(chrono::DateTime::<chrono::Utc>::from_utc(dt, chrono::Utc)),
}
}

#[cfg(feature = "convert-chrono")]
Expand Down

0 comments on commit 3a99595

Please sign in to comment.