Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1603

datetime microseconds are rounded instead of truncated

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.7.1, 3.8
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • Environment:
      AWS Lambda (Python 3.6.1)
      pymongo 3.7.0

      datetime objects have a microsecond precision but the dates stored in MongoDB have a millisecond precision, so the value is truncated.

      But some dates may be rounded up instead on AWS Lambda (Python 3.6.1).
      3000-01-01 01:01:01.999999 is rounded up to 3000-01-01 01:01:02
      while
      3000-01-01 01:01:01.999900 or
      2000-01-01 01:01:01.999999 are truncated.

      It is due to a loss of precision in float operations on that platform when the internal representation exceeds a certain size.
      The conversion to milliseconds code can truncate the microsecond part before adding it to the number of seconds since the epoch to avoid the issue.

      Notes:

      • This issue did not appear on Linux with Python 3.6.1.
      • The datetime.timestamp() standard library method on AWS Lambda has the same rounding issue.

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            yves.duhem Yves Duhem
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: