Installation
pip install readabledelta
Usage examples
The readabledelta is just a more human-friendly printable version of timedelta. The public interface is equivalent to timedelta, only printing behaviour has been modified.
It’s easy to confuse hours/minutes with minutes/seconds in the default formatting of timedeltas
>>> lunchtime = datetime(year=2015, month=5, day=27, hour=12)
>>> right_now = datetime(year=2015, month=5, day=27, hour=13, minute=5)
>>> 'Lunch was {} ago'.format(delta)
'Lunch was 1:05:00 ago'
>>> 'Lunch was {} ago'.format(readabledelta(delta))
'Lunch was 1 hour and 5 minutes ago'
For negative timedeltas, the default representation is more machine-friendly than human-friendly: “an hour and five minutes” back is easier for people to understand than the weird but technically-correct “negative one day plus 22 hours and 55 minutes”
>>> '{}'.format(lunchtime - right_now)
'-1 day, 22:55:00'
>>> '{}'.format(readabledelta(lunchtime - right_now))
'-1 hour and 5 minutes'
A readabledelta is a timedelta, compares as you’d expect, and is simple enough not to misbehave.
>>> issubclass(readabledelta, timedelta) True >>> isinstance(readabledelta(), timedelta) True >>> readabledelta() == timedelta() True
This means you can safely add or subtract them to datetime instances, there will be no unpleasant surprises with arithmetic.
Metadata
Release files for readabledelta 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| readabledelta-0.0.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Release files / readabledelta-0.0.2-py2.py3-none-any.whl
| Download URL | readabledelta-0.0.2-py2.py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
8d3b265fc31604ef08b5954ba4bda6d5aa8172811e7a770ea0ecacb585d22234
|
|
BLAKE2b-256 checksum How to use checksums |
78dd1de5700261c0aecc0cee9a732039d83a3c17395ccc3d809ee2ecb86c710a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |