ago 0.0.5 version
* consolidated human and delta2human * fixed docs and tests to reflect consolidation
This commit is contained in:
parent
1e4fe16b72
commit
a2574a05d8
4 changed files with 48 additions and 45 deletions
17
ago.py
17
ago.py
|
|
@ -13,10 +13,16 @@ def delta2dict( delta ):
|
|||
'microsecond' : delta.microseconds
|
||||
}
|
||||
|
||||
def delta2human(delta, precision=2, past_tense='{} ago', future_tense='in {}'):
|
||||
"""Accepts a delta, returns a human readable delta string"""
|
||||
def human(dt, precision=2, past_tense='{} ago', future_tense='in {}'):
|
||||
"""Accept a datetime or timedelta, return a human readable delta string"""
|
||||
delta = dt
|
||||
if type(dt) is not type(timedelta()):
|
||||
delta = datetime.now() - dt
|
||||
|
||||
the_tense = past_tense
|
||||
if delta < timedelta(0): the_tense = future_tense
|
||||
if delta < timedelta(0):
|
||||
the_tense = future_tense
|
||||
|
||||
d = delta2dict( delta )
|
||||
hlist = []
|
||||
count = 0
|
||||
|
|
@ -30,11 +36,6 @@ def delta2human(delta, precision=2, past_tense='{} ago', future_tense='in {}'):
|
|||
human_delta = ', '.join( hlist )
|
||||
return the_tense.format(human_delta)
|
||||
|
||||
def human(date_time, precision=2, past_tense='{} ago', future_tense='in {}'):
|
||||
"""Accepts a datetime, returns a human readable delta string"""
|
||||
delta = datetime.now() - date_time
|
||||
return delta2human( delta, precision, past_tense, future_tense )
|
||||
|
||||
if __name__ == "__main__":
|
||||
from test_ago import test_output
|
||||
test_output()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue