The format keyword arguments were mismatched between human and delta2human.

The name of these arguments is still up for discussion.
This commit is contained in:
RussellBallestrini 2013-01-09 09:47:46 -05:00
parent 9e841d1266
commit 3cbd5101b3
3 changed files with 16 additions and 16 deletions

View file

@ -40,7 +40,7 @@ You really only need to worry about *human*.
Here are all the available arguments and defaults::
human(d, precision=2, format_past='{0} ago', format_future='in {0}'):
human(d, precision=2, past_format='{0} ago', future_format='in {0}'):
d
datetime object to make into human readable, required
@ -48,10 +48,10 @@ d
precision
control how verbose the output should look, optional
format_past
past_format
format string used when d is a past datetime, optional
format_future
future_format
format string used when d is a future datetime, optional
@ -99,16 +99,16 @@ Now we will document how to use delta2human and delta2dict::
# create a dictionary out of the timedelta
print delta2dict( delta )
Example format_past and format_future keyword arguments::
Example past_format and future_format keyword arguments::
output1 = human( PAST,
format_past = 'titanic sunk {0} ago',
format_future = 'titanic will sink in {0} from now'
past_format = 'titanic sunk {0} ago',
future_format = 'titanic will sink in {0} from now'
)
output2 = human( FUTURE,
format_past = 'titanic sunk {0} ago',
format_future = 'titanic will sink in {0} from now'
past_format = 'titanic sunk {0} ago',
future_format = 'titanic will sink in {0} from now'
)
print output1

4
ago.py
View file

@ -30,10 +30,10 @@ def delta2human(delta, precision=2, past_format='{0} ago', future_format='in {0}
human_delta = ', '.join( hlist )
return the_format.format(human_delta)
def human(d, precision=2, format_past='{0} ago', format_future='in {0}'):
def human(d, precision=2, past_format='{0} ago', future_format='in {0}'):
"""Pass datetime we will return human delta string"""
delta = datetime.now() - d
return delta2human( delta, precision, format_past, format_future )
return delta2human( delta, precision, past_format, future_format )
if __name__ == "__main__":
from test_ago import test_output

View file

@ -43,15 +43,15 @@ def test_two_day_plural():
def test_past_format():
output = human( PAST,
format_past = 'titanic sunk {0} ago',
format_future = 'titanic will sink in {0} from now'
past_format = 'titanic sunk {0} ago',
future_format = 'titanic will sink in {0} from now'
)
assert 'titanic sunk' in output
def test_future_format():
output = human( FUTURE,
format_past = 'titanic sunk {0} ago',
format_future = 'titanic will sink in {0} from now'
past_format = 'titanic sunk {0} ago',
future_format = 'titanic will sink in {0} from now'
)
assert 'titanic will sink in' in output
@ -69,11 +69,11 @@ def test_output():
print '\nTesting past:\n'
print delta2dict( PAST_DELTA )
print 'Commented ' + delta2human( PAST_DELTA, 3 )
print human( PAST, format_past = "Commented {0} ago" )
print human( PAST, past_format = "Commented {0} ago" )
print '\nTesting future:\n'
print delta2dict( FUTURE_DELTA )
print 'Shutdown ' + delta2human( FUTURE_DELTA, 3 )
print human( FUTURE, format_future = 'Shutdown in {0} from now' )
print human( FUTURE, future_format = 'Shutdown in {0} from now' )
print ''