Commit b77ba978 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

utils.SplitTime: Fix rounding of milliseconds

Reported by Iustin.

It used to return this:
>>> utils.SplitTime(1234.999999999999)
(1234, 1000)

while it should've returned this:
>>> utils.SplitTime(1234.999999999999)
(1235, 0)

Reviewed-by: ultrotter
parent b894f5a8
......@@ -1176,6 +1176,7 @@ def SplitTime(seconds):
@return: Tuple containing (seconds, milliseconds)
"""
seconds = round(seconds, 3)
(seconds, fraction) = divmod(seconds, 1.0)
return (int(seconds), int(round(fraction * 1000, 0)))
......
......@@ -785,6 +785,9 @@ class TestTimeFunctions(unittest.TestCase):
self.assertEqual(utils.SplitTime(1), (1, 0))
self.assertEqual(utils.SplitTime(1.5), (1, 500))
self.assertEqual(utils.SplitTime(1218448917.4809151), (1218448917, 481))
self.assertEqual(utils.SplitTime(123.48012), (123, 480))
self.assertEqual(utils.SplitTime(123.9995), (124, 0))
self.assertEqual(utils.SplitTime(123.999999999), (124, 0))
self.assertEqual(utils.MergeTime((1, 0)), 1.0)
self.assertEqual(utils.MergeTime((1, 500)), 1.5)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment