Skip to content

Commit

Permalink
Fix CI failures
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisanti committed Nov 15, 2022
1 parent cf7e24d commit 555aa19
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions rust-runtime/aws-smithy-types-convert/src/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ pub struct Error {
kind: ErrorKind,
}

impl Error {
fn out_of_range(source: impl Into<Box<dyn StdError + Send + Sync + 'static>>) -> Self {
Self {
kind: ErrorKind::OutOfRange(source.into()),
}
}
}

impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match &self.kind {
Expand Down Expand Up @@ -109,7 +117,7 @@ pub trait DateTimeExt {

/// Converts a [`DateTime`] to a [`time::OffsetDateTime`].
///
/// Returns an [`Error::OutOfRange`] if the time is after
/// Returns an [`Error`] if the time is after
/// `9999-12-31T23:59:59.999Z` or before `-9999-01-01T00:00:00.000Z`.
#[cfg(feature = "convert-time")]
fn to_time(&self) -> Result<time::OffsetDateTime, Error>;
Expand All @@ -123,15 +131,11 @@ impl DateTimeExt for DateTime {
#[cfg(feature = "convert-chrono")]
fn to_chrono_utc(&self) -> Result<chrono::DateTime<chrono::Utc>, Error> {
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))
}
None => Err(Error::out_of_range(format!(
"out-of-range seconds {} or invalid nanoseconds {}",
self.secs(),
self.subsec_nanos()
))),
Some(dt) => Ok(chrono::DateTime::<chrono::Utc>::from_utc(dt, chrono::Utc)),
}
}
Expand Down

0 comments on commit 555aa19

Please sign in to comment.