this release fixes a defect where we were naively stripping timezone data which is only a
valid strategy if the local timezone equals the timezone set in the datetime object.
Special thanks to Chad Birch for the defect report, patch, and tests.
changed setup.py
Refactors the get_delta_from_subject() method for a few benefits:
* Checks type more idiomatically (using isinstance instead of type)
* Raise a TypeError if passed a type that isn't able to be handled
* Return immediately if passed a timedelta, so the rest of the method
doesn't need to be inside an else block
instead of importing division from future we simply use int() to cast
floats to integers.
nosetests: on python2.7 passes
python2 test_ago.py: passes
python3 test_ago.py: passes
TODO: Does nosetests work with python3.x?
branch 'default'
changed ago.py
changed test_ago.py
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