Fix for a bug in the short timeElapsed.

This commit is contained in:
Jeremy Fincher 2004-12-08 20:27:59 +00:00
parent f1cbd065f3
commit 5466544350
2 changed files with 7 additions and 4 deletions

View File

@ -127,10 +127,10 @@ def timeElapsed(elapsed, short=False, leadingZeroes=False, years=True,
""" """
ret = [] ret = []
def format(s, i): def format(s, i):
if i or leadingZeroes or ret:
if short: if short:
ret.append('%s%s' % (i, s[0])) ret.append('%s%s' % (i, s[0]))
else: else:
if leadingZeroes or ret or i:
ret.append(nItems(s, i)) ret.append(nItems(s, i))
elapsed = int(elapsed) elapsed = int(elapsed)
assert years or weeks or days or \ assert years or weeks or days or \

View File

@ -98,6 +98,9 @@ class UtilsTest(SupyTestCase):
'and 2 seconds')]: 'and 2 seconds')]:
self.assertEqual(utils.timeElapsed(now - then), expected) self.assertEqual(utils.timeElapsed(now - then), expected)
def timeElapsedShort(self):
self.assertEqual(utils.timeElapsed(123, short=True), '2m 3s')
def testEachSubstring(self): def testEachSubstring(self):
s = 'foobar' s = 'foobar'
L = ['f', 'fo', 'foo', 'foob', 'fooba', 'foobar'] L = ['f', 'fo', 'foo', 'foob', 'fooba', 'foobar']