-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: bson-1.1.0, bson-1.2.0, bson-1.2.1
-
Component/s: BSON
-
None
In BSON, datetimes are represented in millisecond precision. When serializing a chrono::DateTime with greater precision than milliseconds to a BSON datetime, the extra information is silently discarded. Instead of doing so, we should return an error indicating that the date cannot be represented in BSON.
repro:
let doc = doc! { "date": chrono::Utc.timestamp(100, 5) }; let mut v: Vec<u8> = Vec::new(); doc.to_writer(&mut v).unwrap(); let dout = Document::from_reader(&mut v.as_slice()).unwrap(); assert_eq!(doc, dout);
yields:
thread 'main' panicked at 'assertion failed: `(left == right)` left: `Document({"date": DateTime(1970-01-01T00:01:40.000000005Z)})`, right: `Document({"date": DateTime(1970-01-01T00:01:40Z)})`', src/main.rs:222:5