Skip to content

Commit bee5b02

Browse files
committed
[#64] Saturating timstamp to fit u32 useconds of chrono API
1 parent 7959229 commit bee5b02

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/decoder/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,10 @@ fn decode_bson<R: Read + ?Sized>(reader: &mut R, tag: u8, utf8_lossy: bool) -> D
203203
Some(Integer64Bit) => read_i64(reader).map(Bson::I64),
204204
Some(TimeStamp) => read_i64(reader).map(Bson::TimeStamp),
205205
Some(UtcDatetime) => {
206+
// The int64 is UTC milliseconds since the Unix epoch.
206207
let time = read_i64(reader)?;
207208

208-
match Utc.timestamp_opt(time / 1000, (time % 1000) as u32 * 1000000) {
209+
match Utc.timestamp_opt(time / 1000, ((time % 1000) as u32).saturating_mul(1_000_000)) {
209210
LocalResult::None => Err(DecoderError::InvalidTimestamp(time)),
210211
LocalResult::Ambiguous(..) => Err(DecoderError::AmbiguousTimestamp(time)),
211212
LocalResult::Single(t) => Ok(Bson::UtcDatetime(t)),

0 commit comments

Comments
 (0)