2323
2424use std:: fmt:: { self , Debug , Display } ;
2525
26- use chrono:: { Datelike , SecondsFormat , TimeZone , Utc } ;
26+ use chrono:: { Datelike , NaiveDateTime , SecondsFormat , TimeZone , Utc } ;
2727use serde_json:: { json, Value } ;
2828
2929pub use crate :: document:: Document ;
@@ -287,7 +287,7 @@ impl From<oid::ObjectId> for Bson {
287287
288288impl From < chrono:: DateTime < Utc > > for Bson {
289289 fn from ( a : chrono:: DateTime < Utc > ) -> Bson {
290- Bson :: DateTime ( DateTime ( a) )
290+ Bson :: DateTime ( DateTime :: from ( a) )
291291 }
292292}
293293
@@ -1019,12 +1019,6 @@ impl crate::DateTime {
10191019 pub fn timestamp_millis ( & self ) -> i64 {
10201020 self . 0 . timestamp_millis ( )
10211021 }
1022-
1023- /// If this DateTime is sub-millisecond precision. BSON only supports millisecond precision, so
1024- /// this should be checked before serializing to BSON.
1025- pub ( crate ) fn is_sub_millis_precision ( & self ) -> bool {
1026- self . 0 . timestamp_subsec_micros ( ) % 1000 != 0
1027- }
10281022}
10291023
10301024impl Display for crate :: DateTime {
@@ -1041,7 +1035,12 @@ impl From<crate::DateTime> for chrono::DateTime<Utc> {
10411035
10421036impl < T : chrono:: TimeZone > From < chrono:: DateTime < T > > for crate :: DateTime {
10431037 fn from ( x : chrono:: DateTime < T > ) -> Self {
1044- DateTime ( x. with_timezone ( & Utc ) )
1038+ let dt = x. with_timezone ( & Utc ) ;
1039+
1040+ DateTime ( chrono:: DateTime :: < Utc > :: from_utc (
1041+ NaiveDateTime :: from_timestamp ( dt. timestamp ( ) , dt. timestamp_subsec_millis ( ) * 1_000_000 ) ,
1042+ Utc ,
1043+ ) )
10451044 }
10461045}
10471046
0 commit comments