Skip to content

Commit

Permalink
update chrono APIs to unblock third-party upgrade
Browse files Browse the repository at this point in the history
Summary:
We get deprecated warnings in chrono 0.4.38

```
error: use of deprecated associated function `chrono::NaiveDateTime::from_timestamp_opt`: use `DateTime::from_timestamp` instead
   --> fbcode/hermetic_infra/hermit/detcore/tests/time/mod.rs:193:32
    |
193 |                 NaiveDateTime::from_timestamp_opt(tp.tv_sec, tp.tv_nsec as u32).unwrap();
    |                                ^^^^^^^^^^^^^^^^^^

```

this blocks upgrade of rust third-party

Reviewed By: jagill

Differential Revision: D56829596

fbshipit-source-id: b7d481c647a87511ffad92ece3e3511c44b5c1c3
  • Loading branch information
Mike Lui authored and facebook-github-bot committed May 1, 2024
1 parent 552df53 commit 5ebb3fa
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions detcore/tests/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::ptr;
use std::time;

use chrono::DateTime;
use chrono::NaiveDateTime;
use chrono::Utc;
use detcore::types::NANOS_PER_RCB;
use detcore::types::NANOS_PER_SYSCALL;
Expand Down Expand Up @@ -94,10 +93,7 @@ fn tod_gettimeofday() {
0
);
let tp = unsafe { tp.assume_init() };
let naive_time =
NaiveDateTime::from_timestamp_opt(tp.tv_sec, 1000 * tp.tv_usec as u32).unwrap();

let dt = naive_time.and_utc();
let dt = DateTime::from_timestamp(tp.tv_sec, 1000 * tp.tv_usec as u32).unwrap();
// 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 @@ -115,9 +111,7 @@ fn raw_getimeofday_delta() {
0
);
let tp = unsafe { tp.assume_init() };
let naive_time =
NaiveDateTime::from_timestamp_opt(tp.tv_sec, 1000 * tp.tv_usec as u32).unwrap();
naive_time.and_utc()
DateTime::from_timestamp(tp.tv_sec, 1000 * tp.tv_usec as u32).unwrap()
};
let dt2 = {
let mut tp: MaybeUninit<libc::timeval> = MaybeUninit::uninit();
Expand All @@ -126,9 +120,7 @@ fn raw_getimeofday_delta() {
0
);
let tp = unsafe { tp.assume_init() };
let naive_time =
NaiveDateTime::from_timestamp_opt(tp.tv_sec, 1000 * tp.tv_usec as u32).unwrap();
naive_time.and_utc()
DateTime::from_timestamp(tp.tv_sec, 1000 * tp.tv_usec as u32).unwrap()
};

let delta_ns = diff_nanos(dt1, dt2);
Expand Down Expand Up @@ -161,9 +153,7 @@ fn tod_time() {
|| {
let t = unsafe { libc::time(&mut tloc as *mut i64) };
assert_eq!(t, tloc);
let naive_time = NaiveDateTime::from_timestamp_opt(t, 0).unwrap();

let dt = naive_time.and_utc();
let dt = DateTime::from_timestamp(t, 0).unwrap();
assert_eq!(dt.timestamp(), epoch.timestamp());
},
config,
Expand All @@ -189,10 +179,7 @@ fn tod_clock_gettime() {
0
);
let tp = unsafe { tp.assume_init() };
let naive_time =
NaiveDateTime::from_timestamp_opt(tp.tv_sec, tp.tv_nsec as u32).unwrap();

let dt = naive_time.and_utc();
let dt = DateTime::from_timestamp(tp.tv_sec, tp.tv_nsec as u32).unwrap();
// 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 5ebb3fa

Please sign in to comment.