@@ -30,7 +30,9 @@ pub mod write_query;
30
30
use std:: fmt;
31
31
32
32
use crate :: { Error , ReadQuery , WriteQuery } ;
33
- use consts:: { MILLIS_PER_SECOND , MINUTES_PER_HOUR , NANOS_PER_MILLI , SECONDS_PER_MINUTE } ;
33
+ use consts:: {
34
+ MILLIS_PER_SECOND , MINUTES_PER_HOUR , NANOS_PER_MICRO , NANOS_PER_MILLI , SECONDS_PER_MINUTE ,
35
+ } ;
34
36
35
37
#[ cfg( feature = "derive" ) ]
36
38
pub use influxdb_derive:: InfluxDbWriteable ;
@@ -76,8 +78,8 @@ impl From<Timestamp> for DateTime<Utc> {
76
78
Utc . timestamp_nanos ( nanos. try_into ( ) . unwrap ( ) )
77
79
}
78
80
Timestamp :: Nanoseconds ( nanos) => Utc . timestamp_nanos ( nanos. try_into ( ) . unwrap ( ) ) ,
79
- Timestamp :: Microseconds ( mis ) => {
80
- let nanos = mis / 10000 ;
81
+ Timestamp :: Microseconds ( micros ) => {
82
+ let nanos = micros * NANOS_PER_MICRO ;
81
83
Utc . timestamp_nanos ( nanos. try_into ( ) . unwrap ( ) )
82
84
}
83
85
}
@@ -230,7 +232,7 @@ pub enum QueryType {
230
232
#[ cfg( test) ]
231
233
mod tests {
232
234
use super :: consts:: {
233
- MICROS_PER_NANO , MILLIS_PER_SECOND , MINUTES_PER_HOUR , NANOS_PER_MILLI , SECONDS_PER_MINUTE ,
235
+ MILLIS_PER_SECOND , MINUTES_PER_HOUR , NANOS_PER_MICRO , NANOS_PER_MILLI , SECONDS_PER_MINUTE ,
234
236
} ;
235
237
use crate :: query:: { Timestamp , ValidQuery } ;
236
238
use chrono:: prelude:: { DateTime , TimeZone , Utc } ;
@@ -301,9 +303,9 @@ mod tests {
301
303
}
302
304
#[ test]
303
305
fn test_chrono_datetime_from_timestamp_micros ( ) {
304
- let datetime_from_timestamp: DateTime < Utc > = Timestamp :: Microseconds ( 1 ) . into ( ) ;
306
+ let datetime_from_timestamp: DateTime < Utc > = Timestamp :: Microseconds ( 2 ) . into ( ) ;
305
307
assert_eq ! (
306
- Utc . timestamp_nanos( ( 1 / MICROS_PER_NANO ) . try_into( ) . unwrap( ) ) ,
308
+ Utc . timestamp_nanos( ( 2 * NANOS_PER_MICRO ) . try_into( ) . unwrap( ) ) ,
307
309
datetime_from_timestamp
308
310
)
309
311
}
0 commit comments