Skip to main content

Common datetime operations missing from the standard library.

Project description

philiprehberger-datetime-kit

Tests PyPI version Last updated

Common datetime operations missing from the standard library.

Installation

pip install philiprehberger-datetime-kit

Usage

from philiprehberger_datetime_kit import business_days, date_range, is_weekend, relative

# Count business days between two dates
count = business_days("2026-03-16", "2026-03-20")  # 4

Business Days with Holidays

from philiprehberger_datetime_kit import business_days

count = business_days("2026-03-16", "2026-03-20", holidays=["2026-03-18"])  # 3

Date Range

from philiprehberger_datetime_kit import date_range

for d in date_range("2026-03-01", "2026-03-05"):
    print(d)

Relative Time

from philiprehberger_datetime_kit import relative

tomorrow = relative(days=1)
one_hour_ago = relative(hours=-1)

Weekend Check

from philiprehberger_datetime_kit import is_weekend

is_weekend(date(2026, 4, 4))  # True (Saturday)
is_weekend(date(2026, 4, 6))  # False (Monday)

Next Business Day

from philiprehberger_datetime_kit import next_business_day
from datetime import date

next_business_day(date(2026, 4, 3))  # date(2026, 4, 6) — skips weekend
next_business_day(date(2026, 4, 3), holidays=[date(2026, 4, 6)])  # date(2026, 4, 7)

Start and End of Period

from philiprehberger_datetime_kit import start_of, end_of

start = start_of("month")   # first moment of current month
end = end_of("day")         # last moment of today

Add Business Days

from philiprehberger_datetime_kit import add_business_days

result = add_business_days("2026-04-06", 5)  # skips weekends
result = add_business_days("2026-04-06", 3, holidays=["2026-04-07"])

Human-Readable Time Ago

from philiprehberger_datetime_kit import time_ago
from datetime import datetime, timezone

past = datetime(2026, 4, 6, 10, 0, 0, tzinfo=timezone.utc)
time_ago(past)  # "3 hours ago" (depends on current time)

Format Duration

from philiprehberger_datetime_kit import format_duration

format_duration(3661)   # "1h 1m 1s"
format_duration(45)     # "45s"
format_duration(0.5)    # "500ms"

API

Function / Class Description
business_days(start, end, holidays?) Count business days (Mon-Fri) between two dates
date_range(start, end, step?) Yield dates from start to end inclusive
is_weekend(dt?) Check if a date falls on a weekend
next_business_day(dt?, holidays?) Return the next business day (Mon-Fri, excluding holidays)
relative(days?, hours?, minutes?, seconds?) Return UTC now offset by the given delta
start_of(unit, dt?) Start of day/week/month/year
end_of(unit, dt?) End of day/week/month/year
add_business_days(start, days, holidays?) Add N business days to a date, skipping weekends and holidays
time_ago(dt?, now?) Human-readable relative time string ("3 hours ago", "just now")
format_duration(seconds) Format seconds as compact string ("2h 30m", "45s")

Development

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

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

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_datetime_kit-0.3.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

philiprehberger_datetime_kit-0.3.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_datetime_kit-0.3.0.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_datetime_kit-0.3.0.tar.gz
Algorithm Hash digest
SHA256 1e96fc6dd0fe1c84d99a6a3837ed05a3ea32e7430b027b6ce82b04e82eb40a96
MD5 144972561df9ae1358ece6155eaab09a
BLAKE2b-256 6d7a9cdea7b79934cc59fb5960647c9147698409ef2411ff3c7cbd0855a3754f

See more details on using hashes here.

File details

Details for the file philiprehberger_datetime_kit-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_datetime_kit-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58f4ed045df52bb9f3c7c63e557113d9d3a649b76155f3eff9c15d357b23808a
MD5 2c48d5bd8361f724384f877f0d71d15f
BLAKE2b-256 e46bf42a9c897a9cc944cd613be9926469ed95beb92c32d9314bee64f88eecc9

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