Uploaded image for project: 'Rust Driver'
  1. Rust Driver
  2. RUST-816

bson::DateTime from chrono::DateTime may failed to serialization(From<chrono> should change to TryFrom<chrono>))

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: None
    • Component/s: BSON

        1. bug description

       

      bson::DateTime from chrono::DateTime may failed to serialization

       

        1. step to reproduce

      git clone https://github.com/pymongo/mongodb_bson_datetime_bug

      cd mongodb_bson_datetime_bug && cargo b

       

        1. 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

       

       

        1. 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>

      [link title

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            os.popen@gmail.com rust matcher
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: