Find a file
2013-01-08 20:43:48 -05:00
.hgignore first commit, packaged on pypi, easy_install ago! 2012-06-29 19:25:55 -04:00
ago.py Integrated David Beitey's code (https://bitbucket.org/davidjb) 2013-01-08 20:43:48 -05:00
README.rst Update README.rst to document future human deltas 2013-01-07 21:37:34 -05:00
setup.py David Beitey suggested adjusting README to README.rst 2013-01-07 21:16:00 -05:00
test_ago.py Integrated David Beitey's code (https://bitbucket.org/davidjb) 2013-01-08 20:43:48 -05:00

How to install
===================

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
==================

The ago module comes with three functions: 

#. human
#. delta2human
#. delta2dict

You really only need to worry about *human*::

 from ago import human, delta2human, delta2dict
 
 from datetime import datetime
 from datetime import timedelta

 # pretend this was stored in database
 db_date = datetime( 
   year = 2010, 
   month=5, 
   day=4, 
   hour=6, 
   minute=54, 
   second=33, 
   microsecond=4000
  )

 # to find out how long ago, use the human function
 print 'Created ' + human( db_date ) + ' ago.'
 
 # optionally pass a precision
 print 'Created ' + human( db_date, 3 ) + ' 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::

 # pretend we already have a timedelta object

 # subtract two datetime objects for a timedelta object
 d2 = datetime.now()
 delta = d2 - d1

 # 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


How do I thank you?
==========================

You should follow me on twitter http://twitter.com/russellbal


License
=========================

Public Domain



Public Revision Control
==============================

https://bitbucket.org/russellballestrini/ago