moved human to delta2human and created a new wrapper function

called human which works on datetime objects instead of timedelta objects.

Updated README to document new function usage.
This commit is contained in:
RussellBallestrini 2012-07-29 09:15:03 -04:00
parent 389ee21762
commit 51b63aa576
2 changed files with 35 additions and 17 deletions

39
README
View file

@ -7,9 +7,15 @@ easy_install ago
How to use
==================
Import ago and create a timedelta object::
The ago module comes with three functions:
from ago import delta2dict, human
#. human
#. delta2human
#. delta2dict
You really only need to worry about *human*::
from ago import human, delta2human, delta2dict
from datetime import datetime
@ -24,25 +30,28 @@ Import ago and create a timedelta object::
microsecond=4000
)
# this is right now
d2 = datetime.now()
# to find out how long ago, use the human function
print 'Created ' + human( d1 ) + ' ago.'
# optionally pass a precision
print 'Created ' + human( d1, 3 ) + ' ago.'
print 'Created ' + human( d1, 6 ) + ' ago.'
# subtract the two for a timedelta object
Now we will document how to use delta2human and delta2dict::
# pretend we already have a timedelta object
# subtract two datetime objects for a timedelta object
d2 = datetime.now()
delta = d2 - d1
# create a dictionary out of the timedelta
# not needed but accessable
# display a human readable timedelta from a timedelta
print 'Created ' + delta2human( delta ) + ' ago.'
# create a dictionary out of the timedelta
delta_dict = delta2dict( delta )
print delta_dict
# display a human readable timedelta
print 'Created ' + human( delta ) + ' ago.'
# optionally pass a precision
print 'Created ' + human( delta, 3 ) + ' ago.'
print 'Created ' + human( delta, 6 ) + ' ago.'
How do I thank you?
==========================