summaryrefslogtreecommitdiff
path: root/Lib/test/datetimetester.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-09-04 23:57:25 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-09-04 23:57:25 +0200
commitadfefa527a32e711c1bea9c1ac32c20e9cce0660 (patch)
tree8e03b6d95d1f6f32780d8535aa5b60d411d0646f /Lib/test/datetimetester.py
parent19bbb9af678040e8963edfcfdc30e9f87b106fb9 (diff)
downloadcpython-git-adfefa527a32e711c1bea9c1ac32c20e9cce0660.tar.gz
Issue #23517: Fix implementation of the ROUND_HALF_UP rounding mode in
datetime.datetime.fromtimestamp() and datetime.datetime.utcfromtimestamp(). microseconds sign should be kept before rounding.
Diffstat (limited to 'Lib/test/datetimetester.py')
-rw-r--r--Lib/test/datetimetester.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index f516434bd6..58873af7f6 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -668,6 +668,8 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
eq(td(milliseconds=-0.6/1000), td(microseconds=-1))
eq(td(seconds=0.5/10**6), td(microseconds=1))
eq(td(seconds=-0.5/10**6), td(microseconds=-1))
+ eq(td(seconds=1/2**7), td(microseconds=7813))
+ eq(td(seconds=-1/2**7), td(microseconds=-7813))
# Rounding due to contributions from more than one field.
us_per_hour = 3600e6
@@ -1842,8 +1844,8 @@ class TestDateTime(TestDate):
18000 + 3600 + 2*60 + 3 + 4*1e-6)
def test_microsecond_rounding(self):
- for fts in [self.theclass.fromtimestamp,
- self.theclass.utcfromtimestamp]:
+ for fts in (datetime.fromtimestamp,
+ self.theclass.utcfromtimestamp):
zero = fts(0)
self.assertEqual(zero.second, 0)
self.assertEqual(zero.microsecond, 0)
@@ -1874,6 +1876,12 @@ class TestDateTime(TestDate):
t = fts(0.9999999)
self.assertEqual(t.second, 1)
self.assertEqual(t.microsecond, 0)
+ t = fts(1/2**7)
+ self.assertEqual(t.second, 0)
+ self.assertEqual(t.microsecond, 7813)
+ t = fts(-1/2**7)
+ self.assertEqual(t.second, 59)
+ self.assertEqual(t.microsecond, 992187)
def test_insane_fromtimestamp(self):
# It's possible that some platform maps time_t to double,