datetime microseconds are rounded instead of truncated

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: 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
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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
              Reporter:
              Yves Duhem (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: