Skip to content

Commit

Permalink
replace DateTime::from_utc() with .and_utc()
Browse files Browse the repository at this point in the history
Summary: Preparation to chrono upgrade to 0.4.28 which deprecates `DateTime::from_utc()`.

Reviewed By: zertosh

Differential Revision: D48866817

fbshipit-source-id: 1c3c344c4c076a02cce33c892d7ce1e1ed44db2a
  • Loading branch information
KapJI authored and facebook-github-bot committed Aug 31, 2023
1 parent 264a261 commit c380628
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions detcore/tests/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn tod_gettimeofday() {
let naive_time =
NaiveDateTime::from_timestamp_opt(tp.tv_sec, 1000 * tp.tv_usec as u32).unwrap();

let dt = DateTime::<Utc>::from_utc(naive_time, Utc);
let dt = naive_time.and_utc();
// However exactly we compute logical time, this should be within a small
// fraction of a (logical) second of epoch:
assert!(diff_millis(dt, epoch) < 100);
Expand All @@ -117,7 +117,7 @@ fn raw_getimeofday_delta() {
let tp = unsafe { tp.assume_init() };
let naive_time =
NaiveDateTime::from_timestamp_opt(tp.tv_sec, 1000 * tp.tv_usec as u32).unwrap();
DateTime::<Utc>::from_utc(naive_time, Utc)
naive_time.and_utc()
};
let dt2 = {
let mut tp: MaybeUninit<libc::timeval> = MaybeUninit::uninit();
Expand All @@ -128,7 +128,7 @@ fn raw_getimeofday_delta() {
let tp = unsafe { tp.assume_init() };
let naive_time =
NaiveDateTime::from_timestamp_opt(tp.tv_sec, 1000 * tp.tv_usec as u32).unwrap();
DateTime::<Utc>::from_utc(naive_time, Utc)
naive_time.and_utc()
};

let delta_ns = diff_nanos(dt1, dt2);
Expand Down Expand Up @@ -163,7 +163,7 @@ fn tod_time() {
assert_eq!(t, tloc);
let naive_time = NaiveDateTime::from_timestamp_opt(t, 0).unwrap();

let dt = DateTime::<Utc>::from_utc(naive_time, Utc);
let dt = naive_time.and_utc();
assert_eq!(dt.timestamp(), epoch.timestamp());
},
config,
Expand Down Expand Up @@ -192,7 +192,7 @@ fn tod_clock_gettime() {
let naive_time =
NaiveDateTime::from_timestamp_opt(tp.tv_sec, tp.tv_nsec as u32).unwrap();

let dt = DateTime::<Utc>::from_utc(naive_time, Utc);
let dt = naive_time.and_utc();
// However exactly we compute logical time, this should be within a small
// fraction of a (logical) second of epoch:
assert!(diff_millis(dt, epoch) < 100);
Expand Down

0 comments on commit c380628

Please sign in to comment.