From e6809e8132309d20896e83dc0cca1108d84f9e59 Mon Sep 17 00:00:00 2001 From: Bernie Hackett Date: Fri, 22 Aug 2014 14:45:04 -0700 Subject: [PATCH] PYTHON-346 - Eliminate unnecessary datetime.replace call --- bson/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bson/__init__.py b/bson/__init__.py index f9a1bb8c9..791d09007 100644 --- a/bson/__init__.py +++ b/bson/__init__.py @@ -208,13 +208,15 @@ def _get_date(data, position, opts): """Decode a BSON datetime to python datetime.datetime.""" end = position + 8 millis = _UNPACK_LONG(data[position:end])[0] - diff = millis % 1000 + diff = ((millis % 1000) + 1000) % 1000 seconds = (millis - diff) / 1000 + micros = diff * 1000 if opts[1]: - dtime = EPOCH_AWARE + datetime.timedelta(seconds=seconds) + return EPOCH_AWARE + datetime.timedelta( + seconds=seconds, microseconds=micros), end else: - dtime = EPOCH_NAIVE + datetime.timedelta(seconds=seconds) - return dtime.replace(microsecond=diff * 1000), end + return EPOCH_NAIVE + datetime.timedelta( + seconds=seconds, microseconds=micros), end def _get_code(data, position, opts):