File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,6 @@ libc = "0.2"
31
31
rand = " 0.7"
32
32
serde = { version = " 1.0" , features = [" derive" ] }
33
33
serde_json = { version = " 1.0" , features = [" preserve_order" ] }
34
- time = " 0.1"
35
34
linked-hash-map = " 0.5.3"
36
35
hex = " 0.4.2"
37
36
md5 = " 0.7.0"
Original file line number Diff line number Diff line change 1
1
//! ObjectId
2
2
3
3
use std:: {
4
+ convert:: TryInto ,
4
5
error,
5
6
fmt,
6
7
result,
7
8
sync:: atomic:: { AtomicUsize , Ordering } ,
9
+ time:: SystemTime ,
8
10
} ;
9
11
10
12
use byteorder:: { BigEndian , ByteOrder } ;
@@ -137,8 +139,12 @@ impl ObjectId {
137
139
// Generates a new timestamp representing the current seconds since epoch.
138
140
// Represented in Big Endian.
139
141
fn gen_timestamp ( ) -> [ u8 ; 4 ] {
140
- let timespec = time:: get_time ( ) ;
141
- let timestamp = timespec. sec as u32 ;
142
+ let timestamp = SystemTime :: now ( )
143
+ . duration_since ( SystemTime :: UNIX_EPOCH )
144
+ . expect ( "system clock is before 1970" )
145
+ . as_secs ( )
146
+ . try_into ( )
147
+ . unwrap ( ) ; // will succeed until 2106 since timestamp is unsigned
142
148
143
149
let mut buf: [ u8 ; 4 ] = [ 0 ; 4 ] ;
144
150
BigEndian :: write_u32 ( & mut buf, timestamp) ;
You can’t perform that action at this time.
0 commit comments