Skip to main content

A lightweight, flexible business duration calculator.

Project description

bizdurr

Tests PyPI version Python versions License: MIT

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,
    business_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
    business_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,
    business_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,
    business_timezone="America/New_York",
    overrides={
        # Christmas Eve: half day
        "2025-12-24": {"start": "09:00", "end": "12:00"},
    },
)

Timezone Handling

The business_timezone parameter specifies where the business is located. All business hours are interpreted in this timezone, and all calculations are performed relative to it.

from datetime import datetime
from zoneinfo import ZoneInfo
from bizdurr import BusinessDuration

# Business is located in New York
bd = BusinessDuration(
    business_hours={"start": "09:00", "end": "17:00"},
    business_timezone="America/New_York",
)

# 1. Naive datetimes are assumed to be in the business timezone
bd.calculate(
    datetime(2025, 12, 8, 10, 0),
    datetime(2025, 12, 8, 15, 0)
)  # 5 hours

# 2. Aware datetimes in the same timezone work as expected
eastern = ZoneInfo("America/New_York")
bd.calculate(
    datetime(2025, 12, 8, 10, 0, tzinfo=eastern),
    datetime(2025, 12, 8, 15, 0, tzinfo=eastern)
)  # 5 hours

# 3. Aware datetimes in different timezones are converted automatically
pacific = ZoneInfo("America/Los_Angeles")
bd.calculate(
    datetime(2025, 12, 8, 7, 0, tzinfo=pacific),   # 7 AM Pacific = 10 AM Eastern
    datetime(2025, 12, 8, 12, 0, tzinfo=pacific)   # 12 PM Pacific = 3 PM Eastern
)  # 5 hours

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-2.0.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

bizdurr-2.0.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bizdurr-2.0.0.tar.gz
Algorithm Hash digest
SHA256 983278dc6a484d405c8428245b06a9bed033f1128f01cbf76ca99c8892ba1b5f
MD5 40618037bfdbfd64702bfc0b19f54487
BLAKE2b-256 801f89c715a40e591672504ccd23bba9c4e134c889ef6c0a157f6593d47a9a1d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for bizdurr-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38aab35f9259d7cfc9d000012f1782a344ba0ec920394c8e53f1f1c28487b927
MD5 366f8ca9592923a2dc13be9e38cf6eb8
BLAKE2b-256 0c3f8bdffd4a9856b4bda43734c550822dc0643c276c86c399c6cec26544cc2b

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