diff --git a/influxdb/src/query/consts.rs b/influxdb/src/query/consts.rs index b302599..96c0b36 100644 --- a/influxdb/src/query/consts.rs +++ b/influxdb/src/query/consts.rs @@ -2,6 +2,4 @@ pub const MINUTES_PER_HOUR: u128 = 60; pub const SECONDS_PER_MINUTE: u128 = 60; pub const MILLIS_PER_SECOND: u128 = 1000; pub const NANOS_PER_MILLI: u128 = 1_000_000; - -#[cfg(test)] -pub const MICROS_PER_NANO: u128 = 1000; +pub const NANOS_PER_MICRO: u128 = 1000; diff --git a/influxdb/src/query/mod.rs b/influxdb/src/query/mod.rs index 0546b2b..ccb3513 100644 --- a/influxdb/src/query/mod.rs +++ b/influxdb/src/query/mod.rs @@ -30,7 +30,9 @@ pub mod write_query; use std::fmt; use crate::{Error, ReadQuery, WriteQuery}; -use consts::{MILLIS_PER_SECOND, MINUTES_PER_HOUR, NANOS_PER_MILLI, SECONDS_PER_MINUTE}; +use consts::{ + MILLIS_PER_SECOND, MINUTES_PER_HOUR, NANOS_PER_MICRO, NANOS_PER_MILLI, SECONDS_PER_MINUTE, +}; #[cfg(feature = "derive")] pub use influxdb_derive::InfluxDbWriteable; @@ -76,8 +78,8 @@ impl From for DateTime { Utc.timestamp_nanos(nanos.try_into().unwrap()) } Timestamp::Nanoseconds(nanos) => Utc.timestamp_nanos(nanos.try_into().unwrap()), - Timestamp::Microseconds(mis) => { - let nanos = mis / 10000; + Timestamp::Microseconds(micros) => { + let nanos = micros * NANOS_PER_MICRO; Utc.timestamp_nanos(nanos.try_into().unwrap()) } } @@ -230,7 +232,7 @@ pub enum QueryType { #[cfg(test)] mod tests { use super::consts::{ - MICROS_PER_NANO, MILLIS_PER_SECOND, MINUTES_PER_HOUR, NANOS_PER_MILLI, SECONDS_PER_MINUTE, + MILLIS_PER_SECOND, MINUTES_PER_HOUR, NANOS_PER_MICRO, NANOS_PER_MILLI, SECONDS_PER_MINUTE, }; use crate::query::{Timestamp, ValidQuery}; use chrono::prelude::{DateTime, TimeZone, Utc}; @@ -301,9 +303,9 @@ mod tests { } #[test] fn test_chrono_datetime_from_timestamp_micros() { - let datetime_from_timestamp: DateTime = Timestamp::Microseconds(1).into(); + let datetime_from_timestamp: DateTime = Timestamp::Microseconds(2).into(); assert_eq!( - Utc.timestamp_nanos((1 / MICROS_PER_NANO).try_into().unwrap()), + Utc.timestamp_nanos((2 * NANOS_PER_MICRO).try_into().unwrap()), datetime_from_timestamp ) }