refactoring

changed ago.py
This commit is contained in:
russellballestrini 2016-09-21 16:56:23 -04:00
parent 5c9ba685d2
commit c4a62c9690

9
ago.py
View file

@ -3,6 +3,8 @@ from datetime import (
timedelta,
)
units = ('year', 'day', 'hour', 'minute', 'second', 'microsecond')
def get_delta_from_subject(subject):
subject_type = type(subject)
if subject_type is timedelta:
@ -42,17 +44,12 @@ def human(subject, precision=2, past_tense='{} ago', future_tense='in {}', abbre
:returns: Human readable timedelta string (Str)
"""
delta = get_delta_from_subject(subject)
# determine if the_tense is past_tense or future_tense.
the_tense = past_tense
if delta < timedelta(0):
the_tense = future_tense
the_tense = future_tense if delta < timedelta(0) else past_tense
d = delta2dict( delta )
hlist = []
count = 0
units = ( 'year', 'day', 'hour', 'minute', 'second', 'microsecond' )
# start building up the output in the hlist.
for unit in units: