fix millisecs versus microsecs

changed ago.py
changed setup.py
changed test_ago.py
This commit is contained in:
russellballestrini 2017-10-14 20:49:50 -04:00
parent ddcd765260
commit 36102bba88
3 changed files with 14 additions and 7 deletions

12
ago.py
View file

@ -3,7 +3,7 @@ from datetime import (
timedelta,
)
units = ('year', 'day', 'hour', 'minute', 'second', 'microsecond')
units = ('year', 'day', 'hour', 'minute', 'second', 'millisecond', 'microsecond')
def get_delta_from_subject(subject):
subject_type = type(subject)
@ -28,7 +28,8 @@ def delta2dict(delta):
'hour' : int(delta.seconds / 3600),
'minute' : int(delta.seconds / 60) % 60,
'second' : delta.seconds % 60,
'microsecond' : delta.microseconds
'millisecond' : delta.microseconds/1000,
'microsecond' : delta.microseconds%1000,
}
def human(subject, precision=2, past_tense='{} ago', future_tense='in {}', abbreviate=False):
@ -56,7 +57,12 @@ def human(subject, precision=2, past_tense='{} ago', future_tense='in {}', abbre
if count >= precision: break # met precision
if d[ unit ] == 0: continue # skip 0's
if abbreviate:
abr = 'mu' if unit == 'microsecond' else unit[0]
if unit == 'millisecond':
abr = 'ms'
elif unit == 'microsecond':
abr = 'um'
else:
abr = unit[0]
hlist.append('{}{}'.format(d[unit], abr))
else:
s = '' if d[ unit ] == 1 else 's' # handle plurals