philiprehberger-timeago
Convert timestamps to relative time phrases like "3 hours ago".
Installation
pip install philiprehberger-timeago
Usage
from philiprehberger_timeago import timeago, timedelta_human
from datetime import datetime, timedelta, timezone
now = datetime.now(timezone.utc)
timeago(now - timedelta(seconds=30)) # "30 seconds ago"
timeago(now - timedelta(hours=3)) # "3 hours ago"
timeago(now - timedelta(days=1)) # "yesterday"
timeago(now + timedelta(days=7)) # "in 1 week"
# Unix timestamps
timeago(1709913600)
# Duration formatting
timedelta_human(timedelta(hours=3, minutes=25)) # "3 hours, 25 minutes"
Compact age
from philiprehberger_timeago import format_age
from datetime import datetime, timedelta, timezone
now = datetime.now(timezone.utc)
format_age(now - timedelta(seconds=5)) # "5s"
format_age(now - timedelta(minutes=3)) # "3m"
format_age(now - timedelta(hours=2)) # "2h"
format_age(now - timedelta(days=4)) # "4d"
format_age(now + timedelta(hours=1)) # "-1h" (future)
Numeric mode
from philiprehberger_timeago import timeago
from datetime import datetime, timedelta, timezone
now = datetime.now(timezone.utc)
timeago(now - timedelta(seconds=5), numeric=True) # "5 seconds ago" (not "just now")
timeago(now - timedelta(days=1), numeric=True) # "1 day ago" (not "yesterday")
timeago(now + timedelta(days=1), numeric=True) # "in 1 day" (not "tomorrow")
API
| Function / Class | Description |
|---|---|
timeago(dt, now=None, numeric=False) |
Relative time phrase from datetime, date, or Unix timestamp; numeric=True forces numeric phrasing |
format_age(dt, now=None) |
Compact age string like 5s, 3m, 2h, 4d, 1mo, 2y (future prefixed with -) |
timedelta_human(td) |
Format a timedelta as readable duration |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Metadata
Release files for philiprehberger-timeago 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| philiprehberger_timeago-0.2.0.tar.gz | 183.1 kB | Without provenance | Details for philiprehberger_timeago-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| philiprehberger_timeago-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for philiprehberger_timeago-0.2.0-py3-none-any.whl |
Total release size: 188.2 kB
Release files / philiprehberger_timeago-0.2.0.tar.gz
| Download URL | philiprehberger_timeago-0.2.0.tar.gz |
|---|---|
| Size | 183.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30f57163dd59612f49d95552f85da8f593249aa5ce32caec74128550d2229fb4
|
|
BLAKE2b-256 checksum How to use checksums |
fa51689192b6a4684ef9bf96c2465f45224dda33cee0f7551ff73c11a44c646a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / philiprehberger_timeago-0.2.0-py3-none-any.whl
| Download URL | philiprehberger_timeago-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6dae389807c740a3d1e988c8027e0122b2a3049ec1c52c8dd57c605a16e51321
|
|
BLAKE2b-256 checksum How to use checksums |
8b5c80b340a6276bbce59fdc7a2e13bd3fde84de9ccc2960af987ddc5d63e346
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for philiprehberger-timeago 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.