diff --git a/ago.py b/ago.py index 4ba3615..d85caff 100644 --- a/ago.py +++ b/ago.py @@ -1,4 +1,3 @@ -from __future__ import division from datetime import datetime from datetime import timedelta @@ -6,11 +5,11 @@ def delta2dict( delta ): """Accepts a delta, returns a dictionary of units""" delta = abs( delta ) return { - 'year' : delta.days // 365 , - 'day' : delta.days % 365 , - 'hour' : delta.seconds // 3600 , - 'minute' : (delta.seconds // 60) % 60 , - 'second' : delta.seconds % 60 , + 'year' : int(delta.days / 365), + 'day' : int(delta.days % 365), + 'hour' : int(delta.seconds / 3600), + 'minute' : int(delta.seconds / 60) % 60, + 'second' : delta.seconds % 60, 'microsecond' : delta.microseconds } diff --git a/test_ago.py b/test_ago.py index a564ef4..31972ce 100644 --- a/test_ago.py +++ b/test_ago.py @@ -4,6 +4,14 @@ from datetime import timedelta from ago import human from ago import delta2dict +try: + from types import StringType as STRING + from types import DictType as DICT +except ImportError: + import builtins + STRING = builtins.str + DICT = builtins.dict + # datetime objects PRESENT = datetime.now() PAST = PRESENT - timedelta( 492, 58711, 45 ) # days, secs, ms @@ -15,13 +23,13 @@ FUTURE_DELTA = PRESENT - FUTURE ONE_YEAR_FOUR_HOURS_DELTA = timedelta( 365, 14400, 0 ) def test_human_passed_datetime_is_string(): - assert type(human( PAST )) is builtins.str + assert type(human( PAST )) is STRING def test_human_passed_timedelta_is_string(): - assert type(human( PAST_DELTA )) is builtins.str + assert type(human( PAST_DELTA )) is STRING def test_delta2dict_is_dict(): - assert type(delta2dict( PAST_DELTA )) is builtins.dict + assert type(delta2dict( PAST_DELTA )) is DICT def test_ago_in_past_human(): assert 'ago' in human( PAST )