Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update chrono APIs #51

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading