Skip to content

Commit 93c4554

Browse files
authored
RUST-765 Update broken usages of BSON library (#340)
1 parent bfb8c27 commit 93c4554

File tree

2 files changed

+5
-15
lines changed
  • src
    • bson_util
    • sdam/description/topology/server_selection/test

2 files changed

+5
-15
lines changed

src/bson_util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ mod test {
308308
"i64": -126i64,
309309
"timestamp": Bson::Timestamp(Timestamp { time: 12233, increment: 34444 }),
310310
"binary": Bson::Binary(Binary{ subtype: BinarySubtype::Generic, bytes: vec![3, 222, 11] }),
311-
"objectid": ObjectId::with_bytes([1; 12]),
311+
"objectid": ObjectId::from_bytes([1; 12]),
312312
"datetime": DateTime::from_utc(
313313
NaiveDateTime::from_timestamp(4444333221, 0),
314314
Utc,

src/sdam/description/topology/server_selection/test/mod.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::time::Duration;
22

3-
use bson::{doc, DateTime as BsonDateTime};
4-
use chrono::{DateTime, NaiveDateTime, Utc};
3+
use bson::doc;
4+
use chrono::{TimeZone, Utc};
55
use serde::Deserialize;
66

77
use crate::{
@@ -89,7 +89,7 @@ impl TestServerDescription {
8989
let mut command_response = is_master_response_from_server_type(server_type);
9090
command_response.tags = self.tags;
9191
command_response.last_write = self.last_write.map(|last_write| LastWrite {
92-
last_write_date: utc_datetime_from_millis(last_write.last_write_date),
92+
last_write_date: Utc.timestamp_millis(last_write.last_write_date).into(),
9393
});
9494

9595
let is_master = IsMasterReply {
@@ -104,7 +104,7 @@ impl TestServerDescription {
104104
);
105105
server_desc.last_update_time = self
106106
.last_update_time
107-
.map(|i| utc_datetime_from_millis(i as i64));
107+
.map(|i| Utc.timestamp_millis(i.into()).into());
108108

109109
Some(server_desc)
110110
}
@@ -150,16 +150,6 @@ impl TestServerType {
150150
}
151151
}
152152

153-
fn utc_datetime_from_millis(millis: i64) -> BsonDateTime {
154-
let seconds_portion = millis / 1000;
155-
let nanos_portion = (millis % 1000) * 1_000_000;
156-
157-
let naive_datetime = NaiveDateTime::from_timestamp(seconds_portion, nanos_portion as u32);
158-
let datetime = DateTime::from_utc(naive_datetime, Utc);
159-
160-
BsonDateTime(datetime)
161-
}
162-
163153
fn is_master_response_from_server_type(server_type: ServerType) -> IsMasterCommandResponse {
164154
let mut response = IsMasterCommandResponse::default();
165155

0 commit comments

Comments
 (0)