From aa5cdf2b3b6ff48a4bac6d7a4e97217691438af6 Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Sat, 22 Sep 2018 00:41:35 -0400 Subject: [PATCH] adds pub fn secs(Duration) -> f64 at crate root and InfluxWriter::secs(&self, Duration) -> f64 --- src/influx.rs | 7 ++++++- src/lib.rs | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/influx.rs b/src/influx.rs index 38057d1..5896d5e 100644 --- a/src/influx.rs +++ b/src/influx.rs @@ -258,13 +258,18 @@ impl InfluxWriter { pub fn dur_nanos_u64(&self, d: Duration) -> u64 { dur_nanos(d).max(0) as u64 } #[cfg_attr(feature = "inlines", inline)] - pub fn secs(&self, d: Duration) -> f64 { + pub fn rsecs(&self, d: Duration) -> f64 { ((d.as_secs() as f64 + (d.subsec_nanos() as f64 / 1_000_000_000_f64)) * 1000.0) .round() / 1000.0 } + #[cfg_attr(feature = "inlines", inline)] + pub fn secs(&self, d: Duration) -> f64 { + d.as_secs() as f64 + d.subsec_nanos() as f64 / 1_000_000_000_f64 + } + pub fn tx(&self) -> Sender> { self.tx.clone() } diff --git a/src/lib.rs b/src/lib.rs index 7389b0c..f3ffd93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,7 @@ extern crate zmq; #[cfg(feature = "latency")] extern crate pubsub as pub_sub; +use std::time::Duration; use chrono::{DateTime, Utc, TimeZone as ChronoTZ}; #[allow(unused_imports)] use sloggers::Build; @@ -66,6 +67,11 @@ pub fn nanos(t: DateTime) -> u64 { (t.timestamp() as u64) * 1_000_000_000_u64 + (t.timestamp_subsec_nanos() as u64) } +#[inline] +pub fn secs(d: Duration) -> f64 { + d.as_secs() as f64 + d.subsec_nanos() as f64 / 1_000_000_000_f64 +} + #[inline] pub fn inanos(t: DateTime) -> i64 { t.timestamp() * 1_000_000_000i64 + t.timestamp_subsec_nanos() as i64