Skip to content

Commit

Permalink
avoid deprecated chrono methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxxen committed Mar 19, 2024
1 parent f144f29 commit f0833c9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/types/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ impl FromSql for NaiveDateTime {
TimeUnit::Microsecond => (t / 1_000_000, (t % 1_000_000) * 1000),
TimeUnit::Nanosecond => (t / 1_000_000_000, t % 1_000_000_000),
};
Ok(NaiveDateTime::from_timestamp_opt(secs, nsecs as u32).unwrap())
}
ValueRef::Date32(d) => Ok(NaiveDateTime::from_timestamp_opt(24 * 3600 * (d as i64), 0).unwrap()),
ValueRef::Time64(TimeUnit::Microsecond, d) => {
Ok(NaiveDateTime::from_timestamp_opt(d / 1_000_000, ((d % 1_000_000) * 1_000) as u32).unwrap())
Ok(DateTime::from_timestamp(secs, nsecs as u32).unwrap().naive_utc())
}
ValueRef::Date32(d) => Ok(DateTime::from_timestamp(24 * 3600 * (d as i64), 0).unwrap().naive_utc()),
ValueRef::Time64(TimeUnit::Microsecond, d) => Ok(DateTime::from_timestamp(
d / 1_000_000,
((d % 1_000_000) * 1_000) as u32,
)
.unwrap()
.naive_utc()),
ValueRef::Text(s) => {
let mut s = std::str::from_utf8(s).unwrap();
let format = match s.len() {
Expand Down Expand Up @@ -206,7 +209,7 @@ mod test {
assert_eq!(utc, v2);

let v3: DateTime<Utc> = db.query_row("SELECT '2016-02-23 23:56:04'", [], |r| r.get(0))?;
assert_eq!(utc - Duration::milliseconds(789), v3);
assert_eq!(utc - Duration::try_milliseconds(789).unwrap(), v3);

let v4: DateTime<Utc> = db.query_row("SELECT '2016-02-23 23:56:04.789+00:00'", [], |r| r.get(0))?;
assert_eq!(utc, v4);
Expand Down

0 comments on commit f0833c9

Please sign in to comment.