Skip to content

Commit

Permalink
Moved i128 conversion of nanos into statime.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidv1992 authored and folkertdev committed Aug 16, 2023
1 parent bc5dc49 commit 4c28412
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion statime-linux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ edition = "2021"
arrayvec = { version = "0.7.4", default-features = false }
clap = { version = "4.3.21", features = ["derive"] }
fern = { version = "0.6.2", features = ["colored"] }
fixed = "1.23"
libc = { version = "0.2.147", features = ["extra_traits"] }
log = "0.4.20"
statime = { path = "../statime" }
Expand Down
3 changes: 1 addition & 2 deletions statime-linux/src/clock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::path::Path;

use clock_steering::{unix::UnixClock, TimeOffset};
use fixed::traits::LossyInto;
use statime::{Clock, Duration, Time, TimePropertiesDS};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -102,7 +101,7 @@ impl Clock for LinuxClock {

// Since we want nanos to be in [0,1_000_000_000), we need
// euclidean division and remainder.
let offset_nanos: i128 = time_offset.nanos().lossy_into();
let offset_nanos: i128 = time_offset.nanos_rounded();
let offset = TimeOffset {
seconds: offset_nanos
.div_euclid(1_000_000_000)
Expand Down
4 changes: 4 additions & 0 deletions statime/src/time/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ impl Duration {
self.inner
}

pub fn nanos_rounded(&self) -> i128 {
self.nanos().lossy_into()
}

/// Get the total amount of nanoseconds, losing some precision
pub fn nanos_lossy(&self) -> f64 {
self.nanos().lossy_into()
Expand Down

0 comments on commit 4c28412

Please sign in to comment.