summaryrefslogtreecommitdiffstats
path: root/Lib/datetime.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-09-03 07:06:44 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-09-03 07:06:44 (GMT)
commit2ec5bd6fb22ff71ffbe5987f55a31bc4177e39a6 (patch)
treebc90e17fecec5aa9476146d19ecc02bb59f5e895 /Lib/datetime.py
parent0fa5ef72b731c6884f58c0aa38f648b57004c4db (diff)
downloadcpython-2ec5bd6fb22ff71ffbe5987f55a31bc4177e39a6.zip
cpython-2ec5bd6fb22ff71ffbe5987f55a31bc4177e39a6.tar.gz
cpython-2ec5bd6fb22ff71ffbe5987f55a31bc4177e39a6.tar.bz2
Issue #23517: fromtimestamp() and utcfromtimestamp() methods of
datetime.datetime now round microseconds to nearest with ties going away from zero (ROUND_HALF_UP), as Python 2 and Python older than 3.3, instead of rounding towards -Infinity (ROUND_FLOOR).
Diffstat (limited to 'Lib/datetime.py')
-rw-r--r--Lib/datetime.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/datetime.py b/Lib/datetime.py
index d661460..5ba2ddb 100644
--- a/Lib/datetime.py
+++ b/Lib/datetime.py
@@ -1384,7 +1384,7 @@ class datetime(date):
converter = _time.localtime if tz is None else _time.gmtime
t, frac = divmod(t, 1.0)
- us = int(frac * 1e6)
+ us = _round_half_up(frac * 1e6)
# If timestamp is less than one microsecond smaller than a
# full second, us can be rounded up to 1000000. In this case,
@@ -1404,7 +1404,7 @@ class datetime(date):
def utcfromtimestamp(cls, t):
"""Construct a naive UTC datetime from a POSIX timestamp."""
t, frac = divmod(t, 1.0)
- us = int(frac * 1e6)
+ us = _round_half_up(frac * 1e6)
# If timestamp is less than one microsecond smaller than a
# full second, us can be rounded up to 1000000. In this case,