Converted timeElapsed to use nItems.

This commit is contained in:
Jeremy Fincher 2003-09-05 06:50:06 +00:00
parent 20036816c8
commit 15f4ad8e60

View File

@ -115,55 +115,31 @@ def timeElapsed(elapsed, leadingZeroes=False, years=True, weeks=True,
if leadingZeroes or yrs: if leadingZeroes or yrs:
if yrs: if yrs:
leadingZeroes = True leadingZeroes = True
if yrs != 1: ret.append(nItems(yrs, 'year'))
yrs = '%s years' % yrs
else:
yrs = '1 year'
ret.append(yrs)
if weeks: if weeks:
wks, elapsed = elapsed // 604800, elapsed % 604800 wks, elapsed = elapsed // 604800, elapsed % 604800
if leadingZeroes or wks: if leadingZeroes or wks:
if wks: if wks:
leadingZeroes = True leadingZeroes = True
if wks != 1: ret.append(nItems(wks, 'week'))
wks = '%s weeks' % wks
else:
wks = '1 week'
ret.append(wks)
if days: if days:
ds, elapsed = elapsed // 86400, elapsed % 86400 ds, elapsed = elapsed // 86400, elapsed % 86400
if leadingZeroes or ds: if leadingZeroes or ds:
if ds: if ds:
leadingZeroes = True leadingZeroes = True
if ds != 1: ret.append(nItems(ds, 'day'))
ds = '%s days' % ds
else:
ds = '1 day'
ret.append(ds)
if hours: if hours:
hrs, elapsed = elapsed // 3600, elapsed % 3600 hrs, elapsed = elapsed // 3600, elapsed % 3600
if leadingZeroes or hrs: if leadingZeroes or hrs:
if hrs: if hrs:
leadingZeroes = True leadingZeroes = True
if hrs != 1: ret.append(nItems(hrs, 'hour'))
hrs = '%s hours' % hrs
else:
hrs = '1 hour'
ret.append(hrs)
if minutes or seconds: if minutes or seconds:
mins, secs = elapsed // 60, elapsed % 60 mins, secs = elapsed // 60, elapsed % 60
if leadingZeroes or mins: if leadingZeroes or mins:
if mins != 1: ret.append(nItems(mins, 'minute'))
mins = '%s minutes' % mins
else:
mins = '1 minute'
ret.append(mins)
if seconds: if seconds:
if secs != 1: ret.append(nItems(secs, 'second'))
secs = '%s seconds' % secs
else:
secs = '1 second'
ret.append(secs)
if len(ret) == 0: if len(ret) == 0:
raise ValueError, 'Time difference not great enough to be noted.' raise ValueError, 'Time difference not great enough to be noted.'
if len(ret) == 1: if len(ret) == 1: