Skip to main content

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

Project description

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"

API

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

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.1.tar.gz (3.9 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.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for philiprehberger_timeago-0.1.1.tar.gz
Algorithm Hash digest
SHA256 658db59e0f4d19360dcbe804f1a65f2e81e9b1ab8315d38bd58458ac37ee61e0
MD5 0696c445a89223db0a74a5b3e3c10d17
BLAKE2b-256 5c00adde2c3688527f45b7a6a732db729cc7d977918f1e22211fb2da13d8ba8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_timeago-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 09fdbafbb21b32ff51f31a1b64520f0e608533448c22b2cfc1948b0ce4a20af3
MD5 c0e16acee21ba72fc0063303be6ca6a2
BLAKE2b-256 9c8d46df1f56332660cba17a8d5311b513bcdd68ef8ae87f164f1f548b5eff59

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