Upstream wroberts/pytimeparse state of the touched files before a9e844e72e
This commit is contained in:
1 parent
7b055c8116
commit
9b5ce3ede3
2 files changed
+3
-17
No files matched your search
@@ -358,16 +358,6 @@ class TestTimeparse(unittest.TestCase):
|
|||||||
self.assertEqual(timeparse.timeparse('+5.6 weeks'), 3386880)
|
self.assertEqual(timeparse.timeparse('+5.6 weeks'), 3386880)
|
||||||
self.assertEqual(timeparse.timeparse('-5.6 weeks'), -3386880)
|
self.assertEqual(timeparse.timeparse('-5.6 weeks'), -3386880)
|
||||||
|
|
||||||
def test_timeparse_fractional_rounding(self):
|
|
||||||
'''Decimal quantities that equal a whole number of seconds must not be
|
|
||||||
truncated by binary floating-point error (e.g. 2.05 * 60 == 122.999...).'''
|
|
||||||
self.assertEqual(timeparse.timeparse('2.05m'), 123)
|
|
||||||
self.assertEqual(timeparse.timeparse('+2.05m'), 123)
|
|
||||||
self.assertEqual(timeparse.timeparse('-2.05m'), -123)
|
|
||||||
self.assertEqual(timeparse.timeparse('4.1m'), 246)
|
|
||||||
self.assertEqual(timeparse.timeparse('1.13h'), 4068)
|
|
||||||
self.assertEqual(timeparse.timeparse('8.03h'), 28908)
|
|
||||||
|
|
||||||
def test_doctest(self):
|
def test_doctest(self):
|
||||||
'''Run timeparse doctests.'''
|
'''Run timeparse doctests.'''
|
||||||
self.assertTrue(doctest.testmod(timeparse, raise_on_error=True))
|
self.assertTrue(doctest.testmod(timeparse, raise_on_error=True))
|
||||||
@@ -172,14 +172,10 @@ def timeparse(sval, granularity='seconds'):
|
|||||||
elif ('secs' not in mdict or
|
elif ('secs' not in mdict or
|
||||||
mdict['secs'] is None or
|
mdict['secs'] is None or
|
||||||
mdict['secs'].isdigit()):
|
mdict['secs'].isdigit()):
|
||||||
# we will return an integer. Round (not truncate) the
|
# we will return an integer
|
||||||
# sub-second unit contribution: multiplying a decimal
|
|
||||||
# quantity such as 2.05 minutes by 60 yields a binary
|
|
||||||
# float slightly below the exact value (122.999...), and
|
|
||||||
# int() would truncate it to 122 instead of 123.
|
|
||||||
return (
|
return (
|
||||||
sign * int(round(sum([MULTIPLIERS[k] * float(v) for (k, v) in
|
sign * int(sum([MULTIPLIERS[k] * float(v) for (k, v) in
|
||||||
list(mdict.items()) if k != 'secs' and v is not None]))) +
|
list(mdict.items()) if k != 'secs' and v is not None])) +
|
||||||
(int(mdict['secs'], 10) if mdict['secs'] else 0))
|
(int(mdict['secs'], 10) if mdict['secs'] else 0))
|
||||||
else:
|
else:
|
||||||
# SECS is a float, we will return a float
|
# SECS is a float, we will return a float
|
||||||
|
|||||||
Reference in new issue
Block a user