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
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.
- 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.
- is related to
DRIVERS-937 Require that sub-millisecond precision times are rounded down to nearest millisecond when serializing
- related to
RUBY-2145 bson 4.8.0 rounds Time during serialization to bson/extended json