Update README.rst to document future human deltas
This commit is contained in:
parent
7b58f3d73c
commit
ec3cf8fbfb
1 changed files with 21 additions and 6 deletions
27
README.rst
27
README.rst
|
|
@ -1,8 +1,14 @@
|
||||||
How to install
|
How to install
|
||||||
===================
|
===================
|
||||||
|
|
||||||
easy_install ago
|
There are a number of ways to install this package::
|
||||||
|
|
||||||
|
easy_install ago
|
||||||
|
|
||||||
|
pip install ago
|
||||||
|
|
||||||
|
or specify *ago* under the *setup_requires* list within your
|
||||||
|
*setuptools*-compatible project's *setup.py* file.
|
||||||
|
|
||||||
How to use
|
How to use
|
||||||
==================
|
==================
|
||||||
|
|
@ -18,9 +24,10 @@ You really only need to worry about *human*::
|
||||||
from ago import human, delta2human, delta2dict
|
from ago import human, delta2human, delta2dict
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
# pretend this was stored in database
|
# pretend this was stored in database
|
||||||
d1 = datetime(
|
db_date = datetime(
|
||||||
year = 2010,
|
year = 2010,
|
||||||
month=5,
|
month=5,
|
||||||
day=4,
|
day=4,
|
||||||
|
|
@ -31,11 +38,19 @@ You really only need to worry about *human*::
|
||||||
)
|
)
|
||||||
|
|
||||||
# to find out how long ago, use the human function
|
# to find out how long ago, use the human function
|
||||||
print 'Created ' + human( d1 ) + ' ago.'
|
print 'Created ' + human( db_date ) + ' ago.'
|
||||||
|
|
||||||
# optionally pass a precision
|
# optionally pass a precision
|
||||||
print 'Created ' + human( d1, 3 ) + ' ago.'
|
print 'Created ' + human( db_date, 3 ) + ' ago.'
|
||||||
print 'Created ' + human( d1, 6 ) + ' ago.'
|
print 'Created ' + human( db_date, 6 ) + ' ago.'
|
||||||
|
|
||||||
|
We also support future dates and times::
|
||||||
|
|
||||||
|
present = datetime.now()
|
||||||
|
past = present - timedelta( 492, 58711, 45 ) # days, secs, ms
|
||||||
|
future = present + timedelta( 2, 12447, 963 ) # days, secs, ms
|
||||||
|
|
||||||
|
print 'Shutdown in ' + human( future )
|
||||||
|
|
||||||
Now we will document how to use delta2human and delta2dict::
|
Now we will document how to use delta2human and delta2dict::
|
||||||
|
|
||||||
|
|
@ -48,7 +63,7 @@ Now we will document how to use delta2human and delta2dict::
|
||||||
# display a human readable timedelta from a timedelta
|
# display a human readable timedelta from a timedelta
|
||||||
print 'Created ' + delta2human( delta ) + ' ago.'
|
print 'Created ' + delta2human( delta ) + ' ago.'
|
||||||
|
|
||||||
# create a dictionary out of the timedelta
|
# create a dictionary out of the timedelta
|
||||||
delta_dict = delta2dict( delta )
|
delta_dict = delta2dict( delta )
|
||||||
print delta_dict
|
print delta_dict
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue