From c2adaf7ee06eea02ac9c41d2c8335f8ec23608a6 Mon Sep 17 00:00:00 2001 From: Kyle Bloom Date: Tue, 31 Jan 2023 13:54:29 +0000 Subject: [PATCH] fix: Use try into implementation for from_time --- src/types.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/types.rs b/src/types.rs index ac1b9a1d..b6e79097 100644 --- a/src/types.rs +++ b/src/types.rs @@ -173,18 +173,9 @@ impl DateTime { #[allow(clippy::result_unit_err)] #[deprecated(note = "use `DateTime::try_from()`")] pub fn from_time(dt: OffsetDateTime) -> Result { - if dt.year() >= 1980 && dt.year() <= 2107 { - Ok(DateTime { - year: (dt.year()) as u16, - month: (dt.month()) as u8, - day: dt.day(), - hour: dt.hour(), - minute: dt.minute(), - second: dt.second(), - }) - } else { - Err(()) - } + use std::convert::TryInto; + + dt.try_into().map_err(|_err| ()) } /// Gets the time portion of this datetime in the msdos representation