-
Type: Bug
-
Resolution: Duplicate
-
Priority: Critical - P2
-
None
-
Affects Version/s: None
-
Component/s: BSON
-
- bug description
bson::DateTime from chrono::DateTime may failed to serialization
-
- step to reproduce
git clone https://github.com/pymongo/mongodb_bson_datetime_bug
cd mongodb_bson_datetime_bug && cargo b
-
- reason for bug
bson's DateTime use i64 timestamp in miliseconds like javascript, which means it can't contains microsecond or nanosecond
// now would failed to serialization
let now: mongodb::bson::DateTime = chrono::Utc::now().into();
must check chrono's DateTime whether contains microsecond or nanosecond in impl From<chrono> for bson
-
- suggestion
change From<chrono> to TryFrom<chrono>
all bson's DateTime is chrono's DateTime, but not all chrono's DateTime is bson's DateTime
must check chrono's DateTime whether a valid bson's DateTime in From<chrono>
or truncate microsecond and nanosecond on chrono's DateTime
I suggest to move these code to From<chrono>