diff --git a/ago.py b/ago.py index b7acec4..bf876b1 100644 --- a/ago.py +++ b/ago.py @@ -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 diff --git a/setup.py b/setup.py index 3479c47..33ae75d 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup setup( name = 'ago', - version = '0.0.91', + version = '0.0.92', description = 'ago: Human readable timedeltas', keywords = 'ago human readable time deltas timedelta datetime timestamp', long_description = open('README.rst').read(), diff --git a/test_ago.py b/test_ago.py index 859a409..a9620c0 100644 --- a/test_ago.py +++ b/test_ago.py @@ -8,8 +8,8 @@ from ago import delta2dict # datetime objects PRESENT = datetime.now() -PAST = PRESENT - timedelta( 492, 58711, 45 ) # days, secs, ms -FUTURE = PRESENT + timedelta( 2, 12447, 963 ) # days, secs, ms +PAST = PRESENT - timedelta( 492, 58711, 45 ) # days, secs, microseconds +FUTURE = PRESENT + timedelta( 2, 12447, 967742 ) # days, secs, microseconds # timedelta objects PAST_DELTA = PRESENT - PAST @@ -101,7 +101,8 @@ def test_valid_future_dict(): assert past_dict['day'] == 2 assert past_dict['hour'] == 3 assert past_dict['minute'] == 27 - assert past_dict['microsecond'] == 963 + assert past_dict['millisecond'] == 967 + assert past_dict['microsecond'] == 742 def example_usage(): """Test and example usage"""