Skip to content

Commit

Permalink
refactor: Convert impl TryInto<NaiveDateTime> for DateTime to `impl…
Browse files Browse the repository at this point in the history
… TryFrom<DateTime> for NaiveDateTime` (#136)
  • Loading branch information
Pr0methean committed May 19, 2024
1 parent 2148580 commit 3afe549
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ impl TryFrom<NaiveDateTime> for DateTime {
}

#[cfg(feature = "chrono")]
impl TryInto<NaiveDateTime> for DateTime {
impl TryFrom<DateTime> for NaiveDateTime {
type Error = DateTimeRangeError;

fn try_into(self) -> Result<NaiveDateTime, Self::Error> {
let date = NaiveDate::from_ymd_opt(self.year.into(), self.month.into(), self.day.into())
fn try_from(value: DateTime) -> Result<Self, Self::Error> {
let date = NaiveDate::from_ymd_opt(value.year.into(), value.month.into(), value.day.into())
.ok_or(DateTimeRangeError)?;
let time =
NaiveTime::from_hms_opt(self.hour.into(), self.minute.into(), self.second.into())
NaiveTime::from_hms_opt(value.hour.into(), value.minute.into(), value.second.into())
.ok_or(DateTimeRangeError)?;
Ok(NaiveDateTime::new(date, time))
}
Expand Down

0 comments on commit 3afe549

Please sign in to comment.