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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: philiprehberger_timeago-0.1.3.tar.gz
  • Upload date:
  • Size: 4.0 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.3.tar.gz
Algorithm Hash digest
SHA256 2d9119b86d757b5304019f44525490d7c562116f7cfb59c36feade6154fc75e3
MD5 056bfa7358631a3fef6e3582843ff8bf
BLAKE2b-256 6f65c65b6f1de0ca58fd085856944c52fac86514f78af6006fd8f48aeece69d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_timeago-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2d695375652a84c44eb495a29f7ec3103d71566544d02205fad204d9125f4f74
MD5 e42c41c4e0305da1724d455be6ac2ee7
BLAKE2b-256 1d904992f9eb2e8a32e653ea8aac8e47d8bba3e0d72efc031485976d3df8b181

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