Skip to content

Commit

Permalink
Merge pull request #96 from nickbabcock/deprecated-date
Browse files Browse the repository at this point in the history
Fix deprecrated chrono api usage
  • Loading branch information
nickbabcock authored Oct 5, 2023
2 parents a44af63 + a8c91a1 commit 6a8cf32
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/api/cdtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ impl From<CdTime> for DateTime<Utc> {
let CdTime(ns) = v;
let secs = ns / 1_000_000_000;
let left = ns % 1_000_000_000;
Utc.timestamp(secs as i64, left as u32)
Utc.timestamp_opt(secs as i64, left as u32)
.latest()
.unwrap_or_default()
}
}

Expand Down Expand Up @@ -103,13 +105,14 @@ mod tests {
fn test_collectd_to_datetime() {
let v: cdtime_t = nanos_to_collectd(1_000_000_000);
let dt: DateTime<Utc> = CdTime::from(v).into();
assert_eq!(Utc.ymd(1970, 1, 1).and_hms(0, 0, 1), dt);
let res = Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 1);
assert_eq!(res.unwrap(), dt);
}

#[test]
fn test_datetime_to_collectd() {
let dt = Utc.ymd(1970, 1, 1).and_hms(0, 0, 1);
let cd = CdTime::from(dt);
let res = Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 1);
let cd = CdTime::from(res.unwrap());
assert_eq!(cd.0, 1_000_000_000);
}
}
2 changes: 1 addition & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ mod tests {
type_: "ho",
type_instance: None,
host: "ho",
time: Utc.ymd(1970, 1, 1).and_hms(0, 0, 1),
time: Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 1).unwrap(),
interval: Duration::seconds(1),
original_list: &list_t,
original_set: &conv,
Expand Down

0 comments on commit 6a8cf32

Please sign in to comment.