diff --git a/ago.py b/ago.py index de4dbb1..7efe64c 100644 --- a/ago.py +++ b/ago.py @@ -25,11 +25,14 @@ def human(dt, precision=2, past_tense='{} ago', future_tense='in {}'): d = delta2dict( delta ) hlist = [] + count = 0 units = ( 'year', 'day', 'hour', 'minute', 'second', 'microsecond' ) - for unit in units[:precision]: # strip units to precision + for unit in units: + if count >= precision: break # met precision if d[ unit ] == 0: continue # skip 0's s = '' if d[ unit ] == 1 else 's' # handle plurals hlist.append( '%s %s%s' % ( d[unit], unit, s ) ) + count += 1 human_delta = ', '.join( hlist ) return the_tense.format(human_delta)