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

Equality on Bson::DateTime before and after serialization with Serde

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      While writing some test assertions for a web app, I faced an issue with comparing two structs with timestamp fields using `Bson:: DateTime`: The first one being the struct before being serialized and stored in the DB and the second one being the struct after being fetched from the DB and deserialized. The thing is, that the timestamps do not match, because before the serialization, the timestamp has precision to the nanosecond level, while after being serialized, it has precision to the millisecond level.

      After diving into the docs for Chrono, it seems that the implementation changed in some recent version:

      ```
      // Version 0.4.5
      #[derive(Deserialize, Serialize)]
      struct S

      {     #[serde(with = "ts_milliseconds")]     time: DateTime<Utc> }

      // Version 0.4.12
      #[derive(Deserialize, Serialize)]
      struct S

      {     #[serde(with = "ts_nanoseconds")]     time: DateTime<Utc> }

      ```

      This makes me wonder if the bson library is using an old version of Chrono, since I couldn't find any custom implementation for the `Serialize` trait on the `DateTime` Struct.

            Assignee:
            patrick.freed@mongodb.com Patrick Freed
            Reporter:
            moy2010@gmail.com Moises Garcia Marquez
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: