Altered human to support future dates

We should move tests into its own file
This commit is contained in:
RussellBallestrini 2013-01-07 21:12:29 -05:00
parent 6dc3268ff7
commit 237a6f508a

35
ago.py
View file

@ -28,26 +28,31 @@ def human( d1, precision = 2 ):
from datetime import datetime
d2 = datetime.now()
delta = d2 - d1
if d2 < d1: delta = d1 - d2
return delta2human( delta, precision )
def test():
"""Test and example usage"""
from datetime import datetime
d1 = datetime(
year = 2009,
month=5,
day=4,
hour=6,
minute=54,
second=33,
microsecond=4000
)
d2 = datetime.now()
delta = d2 - d1
print 'This is just the ago.py test:'
print delta2dict( delta )
print 'Commented ' + delta2human( delta, 3 ) + ' ago'
print 'Commented ' + human( d1 ) + ' ago'
from datetime import timedelta
present = datetime.now()
past = present - timedelta( 492, 58711, 45 ) # days, secs, ms
future = present + timedelta( 2, 12447, 963 ) # days, secs, ms
pdelta = present - past
fdelta = future - present
print '\nTesting past:\n'
print delta2dict( pdelta )
print 'Commented ' + delta2human( pdelta, 3 ) + ' ago'
print 'Commented ' + human( past ) + ' ago'
print '\nTesting future:\n'
print delta2dict( fdelta )
print 'Shutdown in ' + delta2human( fdelta, 3 )
print 'Shutdown in ' + human( future )
print ''
if __name__ == "__main__": test()