Skip to content

Commit eb5d9d7

Browse files
authored
minor: remove dependency on time crate (#139)
1 parent 4c6066e commit eb5d9d7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ libc = "0.2"
3131
rand = "0.7"
3232
serde = { version = "1.0", features = ["derive"] }
3333
serde_json = { version = "1.0", features = ["preserve_order"] }
34-
time = "0.1"
3534
linked-hash-map = "0.5.3"
3635
hex = "0.4.2"
3736
md5 = "0.7.0"

src/oid.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//! ObjectId
22
33
use std::{
4+
convert::TryInto,
45
error,
56
fmt,
67
result,
78
sync::atomic::{AtomicUsize, Ordering},
9+
time::SystemTime,
810
};
911

1012
use byteorder::{BigEndian, ByteOrder};
@@ -137,8 +139,12 @@ impl ObjectId {
137139
// Generates a new timestamp representing the current seconds since epoch.
138140
// Represented in Big Endian.
139141
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
142148

143149
let mut buf: [u8; 4] = [0; 4];
144150
BigEndian::write_u32(&mut buf, timestamp);

0 commit comments

Comments
 (0)