Skip to main content

Convert timestamps to relative time phrases like '3 hours ago'

Project description

philiprehberger-timeago

Tests PyPI version License

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"

API

  • timeago(dt, now=None) — Relative time phrase from datetime, date, or Unix timestamp
  • timedelta_human(td) — Format a timedelta as readable duration

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_timeago-0.1.5.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_timeago-0.1.5-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_timeago-0.1.5.tar.gz.

File metadata

  • Download URL: philiprehberger_timeago-0.1.5.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for philiprehberger_timeago-0.1.5.tar.gz
Algorithm Hash digest
SHA256 05cbff72b558a9e5b8e2db2d9f0392e1ab471effde8b17bd3caf4556737666c0
MD5 a79d0886e7d222647d8059f0d8a78209
BLAKE2b-256 8fc4df05958b39dc27344985fbba8a8d2f124e71b93e52b68e35a81dae264355

See more details on using hashes here.

File details

Details for the file philiprehberger_timeago-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_timeago-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ea1edfb3de18a7750b6966a8133f72de741e573dda270c800a8bc3c3cfedd257
MD5 eaab32b4e6f28443119b7d815fafea3b
BLAKE2b-256 d71be66f560dbfd49505ef72ffeba4ab94f9e95f2cda790c49e290ff06956b78

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page