From bee5b028b0f446732d05c28520597f3905b0f04b Mon Sep 17 00:00:00 2001 From: "Y. T. Chung" Date: Thu, 28 Jun 2018 21:39:15 +0800 Subject: [PATCH] [#64] Saturating timstamp to fit u32 useconds of chrono API --- src/decoder/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index 4d20b1e5..9e3ec441 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -203,9 +203,10 @@ fn decode_bson(reader: &mut R, tag: u8, utf8_lossy: bool) -> D Some(Integer64Bit) => read_i64(reader).map(Bson::I64), Some(TimeStamp) => read_i64(reader).map(Bson::TimeStamp), Some(UtcDatetime) => { + // The int64 is UTC milliseconds since the Unix epoch. let time = read_i64(reader)?; - match Utc.timestamp_opt(time / 1000, (time % 1000) as u32 * 1000000) { + match Utc.timestamp_opt(time / 1000, ((time % 1000) as u32).saturating_mul(1_000_000)) { LocalResult::None => Err(DecoderError::InvalidTimestamp(time)), LocalResult::Ambiguous(..) => Err(DecoderError::AmbiguousTimestamp(time)), LocalResult::Single(t) => Ok(Bson::UtcDatetime(t)),