Skip to content

Commit

Permalink
[#64] Saturating timstamp to fit u32 useconds of chrono API
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Jun 28, 2018
1 parent 7959229 commit bee5b02
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,10 @@ fn decode_bson<R: Read + ?Sized>(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)),
Expand Down

0 comments on commit bee5b02

Please sign in to comment.