Skip to main content

A lightweight, flexible business duration calculator.

Project description

bizdurr

A lightweight, flexible business duration calculator

Calculate the amount of time that falls within your defined business hours — accounting for weekly schedules, holidays, and per-date overrides.


Installation

uv add bizdurr

Or with pip:

pip install bizdurr

Or install from source:

git clone https://github.com/patclrk/bizdurr.git
cd bizdurr
uv pip install .

Quick Start

from datetime import datetime
from bizdurr import BusinessDuration

# Define your weekly business hours
schedule = {
    "monday":    {"start": "09:00", "end": "17:00"},
    "tuesday":   {"start": "09:00", "end": "17:00"},
    "wednesday": {"start": "09:00", "end": "17:00"},
    "thursday":  {"start": "09:00", "end": "17:00"},
    "friday":    {"start": "09:00", "end": "17:00"},
}

# Create a BusinessDuration instance
bd = BusinessDuration(
    business_hours=schedule,
    timezone="America/New_York",
)

# Calculate the business duration between two datetimes
start = datetime(2025, 12, 8, 8, 0)   # Monday 8:00 AM
end   = datetime(2025, 12, 8, 18, 0)  # Monday 6:00 PM

duration = bd.calculate(start, end)
print(duration)  # 8:00:00 (8 hours of business time)
type(duration)  # <class 'datetime.timedelta'>

Features

Weekly Schedule

Pass a dict mapping weekday names (case-insensitive) to start/end times in HH:MM 24-hour format:

schedule = {
    "monday": {"start": "09:00", "end": "17:00"},
    "tuesday": {"start": "10:00", "end": "16:00"},
    # ...
}

Shorthand Schedule (Monday–Friday)

For a fixed Monday through Friday schedule, use the shorthand format:

bd = BusinessDuration(
    business_hours={"start": "09:00", "end": "17:00"},  # Expands to Mon-Fri
    timezone="America/New_York",
)

This automatically expands to Monday through Friday with the same hours. Weekend days (Saturday and Sunday) are excluded.

Holidays

Exclude specific dates from business hours:

bd = BusinessDuration(
    business_hours=schedule,
    timezone="America/New_York",
    holidays=["2025-12-25", "2026-01-01"],  # ISO date strings or date objects
)

Per-Date Overrides

Override business hours for specific dates (e.g., early close):

bd = BusinessDuration(
    business_hours=schedule,
    timezone="America/New_York",
    overrides={
        # Christmas Eve: half day
        "2025-12-24": {"start": "09:00", "end": "12:00"},
    },
)

Timezone Support

All times are interpreted in the specified IANA timezone:

bd = BusinessDuration(
    business_hours=schedule,
    timezone="Europe/London",
)

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

bizdurr-1.0.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

bizdurr-1.0.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file bizdurr-1.0.0.tar.gz.

File metadata

  • Download URL: bizdurr-1.0.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for bizdurr-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2aaa85e239a7e81ab7c5d8d2bd8b4d170c6b3a4d9fec191cb5dc4e07f2d84020
MD5 d4a3bafe2da17a0a8277fd9c70cd21ba
BLAKE2b-256 2dae507147c96f7070451b0cb92634a7f1cccec2a35207a2add73d18ddc35094

See more details on using hashes here.

File details

Details for the file bizdurr-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: bizdurr-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for bizdurr-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c5b9db957a62e6207f303a2fb9d2a16337d133a5e00ee5838411e9e97f8500d
MD5 75a1907bebf98c1a138fba7e2769c59b
BLAKE2b-256 c01fc2c5e0985f02b037a9a1a9f782691231dc290254c7e0c037bb8f19c4add9

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