A small library for getting human readable time value.
Project description
WhenWasThat
Python module for returning a human readable value for the time between two specified datetime objects. Inspired by whenWasThat() function from BMC Discovery.
Properties
| Property | Details |
|---|---|
| microseconds | Output the total number of microseconds between two datetime objects |
| seconds | Output the total number of seconds between two datetime objects |
| minutes | Output the total number of minutes between two datetime objects |
| hours | Output the total number of hours between two datetime objects |
| days | Output the total number of days between two datetime objects |
| weeks | Output the total number of weeks between two datetime objects |
| months | Output the total number of months between two datetime objects |
| years | Output the total number of years between two datetime objects |
| natural | Output an approximate number of seconds, minutes, hours, days, weeks, months or years between two datetime objects |
Usage Examples
Retrieve number of days between two dates
>>> import datetime as dt
>>> from WhenWasThat import when
>>> first_date = dt.datetime(2006, 10, 27, 11, 59, 32, 343001)
>>> last_date = dt.datetime(2016, 9, 30, 20, 21, 43, 561783)
>>> when(first_date,last_date).days
3626.348740958125
Output a natural approximation of the time between two dates
>>> first_date = dt.datetime(2006, 10, 27, 11, 59, 32, 343001)
>>> last_date = dt.datetime(2016, 9, 30, 20, 21, 43, 561783)
>>> when(first_date,last_date).natural
Approximately 9.9 years ago
Last date is not required (module will calculate from datetime.now())
>>> time_then = dt.datetime(2020, 3, 23, 0, 1, 1, 1)
>>> when(time_then).weeks
75.20358385298611
>>> when(time_then).natural
Approximately 17.5 months ago
How many days since the Titanic sunk?
>>> dt.datetime.now()
datetime.datetime(2021, 8, 31, 10, 20, 59, 979468)
>>> titanic = dt.datetime(1912, 4, 15, 2, 20, 0, 0)
>>> print("The Titanic sunk %s days ago." % round(when(titanic).days))
The Titanic sunk 39950 days ago.
Releases
| Version | Summary | Known Issues | Fixed |
|---|---|---|---|
| Alpha-0.0.1 | Alpha release. | ||
| 0.1.0 | Released to PyPi | ||
| 0.1.1 | Released to PyPI with pytest-based test suite and bug fixes |
| |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
whenwasthat-0.1.1.tar.gz
(4.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file whenwasthat-0.1.1.tar.gz.
File metadata
- Download URL: whenwasthat-0.1.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
072d3831c7de34cafbaf31af7e7477c5b34692a6f9fb0e8a01de8a47271f6aee
|
|
| MD5 |
c2173213b3e7873c8371888982968525
|
|
| BLAKE2b-256 |
dab13ac97e78ffcd43976aa2169f5c543fafe254ca7a07b40b744e3431a6d644
|
File details
Details for the file whenwasthat-0.1.1-py3-none-any.whl.
File metadata
- Download URL: whenwasthat-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ca213084e5d7bfd3aeaeb55a5791891d23829ae39f1aa504d3a87d6d0cae801
|
|
| MD5 |
b76d484b00241addaa41e906ab88a456
|
|
| BLAKE2b-256 |
42c5aa855eecddd0cd5a71c35c5b1661438859c8b4d21c89e5412fc85aed3317
|