Uploaded image for project: 'Swift Driver'
  1. Swift Driver
  2. SWIFT-279

Loss of precision when initializing Date BSONValue from msSinceEpoch

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 0.0.8
    • None
    • None

    Description

      When using the msSinceEpoch initializer in our BSONValue extension of Date, some precision is lost. This initializer is used by the from method, so we can see the error when retrieving Date s from a document.

      e.g.

      let d: Document = ["a": Date(timeIntervalSince1970: 0.001)]
      expect(d["a"] as? Date).to(equal(Date(timeIntervalSince1970: 0.001)))
      

      Fails with:
      expected to equal <1969-12-31 19:00:00.0010>, got <1969-12-31 19:00:00.0000>

      There is also a loss of precision in theĀ msSinceEpoch computed property, as it simply truncates as opposed to rounding.

      Attachments

        Activity

          People

            patrick.freed@mongodb.com Patrick Freed
            patrick.freed@mongodb.com Patrick Freed
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: