Using our own counter, opposed to enumerates, allows us to skip increment::
if d[ unit ] == 0: continue # skip 0's
The continue moves us back to the top of the loop, and which bypasses count += 1. This allows us to have a datetime/timedelta that has a 0 value for a unit, and it will not effect precision fufillment.
For example, review this test::
ONE_YEAR_FOUR_HOURS_DELTA = timedelta( 365, 14400, 0 )
def test_zero_day_is_skipped_display_hour():
_result = human( ONE_YEAR_FOUR_HOURS_DELTA, precision = 2 )
assert 'year' in _result
# day is 0 so it is skipped, so we should show hours ...
assert 'hour' in _result
This test will fail using enumerate or using a slice on the units[:precision] tuple.
and chance of introducing errors, by slicing the the units tuple
by the percision. Removed __main__ because nosetest --with-coverage
was flagging it. It was un-nessasary.
Special thanks to Eric Rasmussen who inspired this commit.
* corrected all tests and documentation to reflect new keyword argument names
* changed example _tense strings to use {} instead of {0}
* cleaned up docstrings
Special thanks to David Beitey (http://davidjb.com/) for supplying code and inspiration for this update!
All changes are backward compatible.
Changelog:
* added support for future dates
* added optional format_past keyword argument string for custom output
* added optional format_future keyword argument string for custom output
* added 13 tests to help prevent regressions
* Updated the README.rst documentation for better coverage