mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Issue #23517: datetime.timedelta constructor now rounds microseconds to nearest
with ties going away from zero (ROUND_HALF_UP), as Python 2 and Python older than 3.3, instead of rounding to nearest with ties going to nearest even integer (ROUND_HALF_EVEN).
This commit is contained in:
parent
8cbb013553
commit
2ec558739e
6 changed files with 26 additions and 34 deletions
|
@ -662,28 +662,24 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
|
|||
# Single-field rounding.
|
||||
eq(td(milliseconds=0.4/1000), td(0)) # rounds to 0
|
||||
eq(td(milliseconds=-0.4/1000), td(0)) # rounds to 0
|
||||
eq(td(milliseconds=0.5/1000), td(microseconds=0))
|
||||
eq(td(milliseconds=-0.5/1000), td(microseconds=0))
|
||||
eq(td(milliseconds=0.5/1000), td(microseconds=1))
|
||||
eq(td(milliseconds=-0.5/1000), td(microseconds=-1))
|
||||
eq(td(milliseconds=0.6/1000), td(microseconds=1))
|
||||
eq(td(milliseconds=-0.6/1000), td(microseconds=-1))
|
||||
eq(td(seconds=0.5/10**6), td(microseconds=0))
|
||||
eq(td(seconds=-0.5/10**6), td(microseconds=0))
|
||||
eq(td(seconds=0.5/10**6), td(microseconds=1))
|
||||
eq(td(seconds=-0.5/10**6), td(microseconds=-1))
|
||||
|
||||
# Rounding due to contributions from more than one field.
|
||||
us_per_hour = 3600e6
|
||||
us_per_day = us_per_hour * 24
|
||||
eq(td(days=.4/us_per_day), td(0))
|
||||
eq(td(hours=.2/us_per_hour), td(0))
|
||||
eq(td(days=.4/us_per_day, hours=.2/us_per_hour), td(microseconds=1))
|
||||
eq(td(days=.4/us_per_day, hours=.2/us_per_hour), td(microseconds=1), td)
|
||||
|
||||
eq(td(days=-.4/us_per_day), td(0))
|
||||
eq(td(hours=-.2/us_per_hour), td(0))
|
||||
eq(td(days=-.4/us_per_day, hours=-.2/us_per_hour), td(microseconds=-1))
|
||||
|
||||
# Test for a patch in Issue 8860
|
||||
eq(td(microseconds=0.5), 0.5*td(microseconds=1.0))
|
||||
eq(td(microseconds=0.5)//td.resolution, 0.5*td.resolution//td.resolution)
|
||||
|
||||
def test_massive_normalization(self):
|
||||
td = timedelta(microseconds=-1)
|
||||
self.assertEqual((td.days, td.seconds, td.microseconds),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue