Skip to main content

workclock

CI PyPI Python versions Typed License: MIT

Fast, correct business-time arithmetic (working hours, SLAs, shifts) for Python, with a Rust core — a maintained replacement for businesstimedelta, with a compatibility layer for existing code.

Documentation · Python reference · Playground · Migrating from businesstimedelta

Status: pre-1.0; the API may still change in a minor release.

Install

pip install workclock
uv add workclock

Requires CPython 3.11 or later. The wheels use the stable ABI (abi3), one per platform: Linux x86_64 and aarch64 (manylinux and musllinux), macOS x86_64 and arm64, and Windows x64. Free-threaded CPython cannot load abi3 wheels. Other platforms build from the sdist, which needs a Rust toolchain.

The wheels bundle the IANA time zone database. They use the system database when there is one, and the bundled copy otherwise, so they need no tzdata package.

Quickstart

A support desk in London works 09:00–17:00 on weekdays with a lunch hour, and is closed on 25 and 28 December 2026. A ticket opened at 16:30 on Christmas Eve with an 8-hour SLA is due at 09:30 on 30 December.

from datetime import date, datetime, time
from zoneinfo import ZoneInfo

from workclock import Break, Holidays, Schedule, WorkDay

london = ZoneInfo("Europe/London")
support = Schedule(
    [
        WorkDay(time(9), time(17)),  # Monday to Friday by default
        Break(time(12), time(13)),
        Holidays([date(2026, 12, 25), date(2026, 12, 28)]),
    ],
    time_zone=london,
)

opened = datetime(2026, 12, 24, 16, 30, tzinfo=london)
support.add(opened, hours=8)  # 2026-12-30 09:30, London time
support.between(opened, datetime(2026, 12, 29, 11, tzinfo=london))  # 2:30:00
support.next_period(opened)  # (16:30, 17:00) on 24 December

Datetimes must be timezone-aware, and results keep the tzinfo you pass in. Zones can be IANA names, zoneinfo.ZoneInfo, pytz zones or datetime.timezone.utc. Errors subclass workclock.WorkclockError and the matching built-in exception.

Special days

A SpecialDay gives chosen dates other working hours, and replaces the WorkDay shifts that start on those dates. Breaks and holidays still apply.

from datetime import date, datetime, time, timezone

from workclock import Schedule, SpecialDay, WorkDay

office = Schedule(
    [
        WorkDay(time(9), time(17)),
        SpecialDay(time(9), time(13), [date(2026, 12, 24)]),  # Christmas Eve
    ]
)
office.between(
    datetime(2026, 12, 24, tzinfo=timezone.utc),
    datetime(2026, 12, 25, tzinfo=timezone.utc),
)  # 4:00:00

Batches and NumPy

between_many, add_many and sub_many take lists of datetimes, or NumPy datetime64 and timedelta64 arrays, and process them in one call:

from datetime import datetime, time, timedelta, timezone

from workclock import Schedule, WorkDay

office = Schedule([WorkDay(time(9), time(17))])
tickets = [datetime(2026, 1, 5, 16, tzinfo=timezone.utc)] * 3
office.add_many(tickets, timedelta(hours=2))  # Tuesday 10:00, three times

Coming from businesstimedelta

Most code written for businesstimedelta runs unchanged on workclock's engine:

import datetime

import workclock.compat as businesstimedelta

rule = businesstimedelta.WorkDayRule(datetime.time(9), datetime.time(17))
friday = datetime.datetime(2026, 1, 9, 16)
friday + businesstimedelta.BusinessTimeDelta(rule, hours=2)  # Monday 10:00 UTC

MIGRATING.md lists where it differs.

Why workclock

Correct

businesstimedelta 1.0.1 has had no release since 2019. workclock fixes:

  • Overnight shifts. A 22:00–06:00 shift counts 0 hours between Monday 22:00 and Tuesday 06:00, and adding 4 hours at Monday 22:00 lands on Wednesday. workclock gives 8 hours and Tuesday 02:00.
  • Crashes past the last holiday (#8, #10): TypeError once a query passes the last date in a holiday list.
  • Infinite loops (#9) when holidays and working hours use different time zones. Every workclock search is bounded.
  • Signed differences (#12): Schedule.between(a, b) is negative when b is before a.
  • DST. Working hours are wall-clock times in each rule's IANA zone, and ambiguous or skipped times resolve the way RFC 5545 and JavaScript Temporal do.

Every rule is specified with examples in DESIGN.md, and the package is checked against a brute-force oracle with property-based tests.

Fast

Medians from a GitHub Actions run on a GitHub-hosted Ubuntu runner (AMD EPYC 7763, 4 cores), against businesstimedelta 1.0.1 and against a loop written by hand for this one schedule with datetime and zoneinfo:

Case businesstimedelta 1.0.1 Standard library workclock vs businesstimedelta vs standard library
One call, a 5½-hour span 169 µs 4.01 µs 3.96 µs 43× 1×
One call, a year with bank holidays 53 ms 719 µs 85.4 µs 620× 8.4×
1,000,000 pairs 9.9 min 9.95 s 2.13 s (between_many on NumPy arrays) 280× 4.7×

For one short span the hand-written loop keeps up: most of workclock's call goes on converting datetimes into and out of Rust. workclock pulls ahead as spans get longer or calls are batched. The loop also handles only this one schedule, without overnight shifts or per-rule time zones.

The same single call takes 7.24 µs through workclock.compat. Runner CPUs vary, so the times move from run to run; the speed-ups, measured within one run, carry over better. benchmarks/RESULTS.md has every case with p95s.

Also for Rust and JavaScript

The same engine ships as the workclock crate and the workclock npm package, with the same results in every language.

Prior art & credits

workclock ports the test suite and the API of businesstimedelta by Sebastiaan Boer, released under the MIT license. The ported API is workclock.compat, and the ported tests run against it in CI. The original copyright notice is kept in NOTICE.

License

MIT

Metadata

Release files for workclock 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for workclock 0.2.0
File Size Uploaded Provenance Actions
workclock-0.2.0.tar.gz 53.5 kB With provenance Details for workclock-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for workclock 0.2.0
File Actions
workclock-0.2.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for workclock-0.2.0-cp311-abi3-win_amd64.whl
workclock-0.2.0-cp311-abi3-musllinux_1_2_x86_64.whl CPython 3.11 abi3 Linux musl 1.2+ x86-64 Details for workclock-0.2.0-cp311-abi3-musllinux_1_2_x86_64.whl
workclock-0.2.0-cp311-abi3-musllinux_1_2_aarch64.whl CPython 3.11 abi3 Linux musl 1.2+ ARM64 Details for workclock-0.2.0-cp311-abi3-musllinux_1_2_aarch64.whl
workclock-0.2.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for workclock-0.2.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
workclock-0.2.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for workclock-0.2.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
workclock-0.2.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for workclock-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
workclock-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for workclock-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 4.2 MB

Release files / workclock-0.2.0.tar.gz

Download URL workclock-0.2.0.tar.gz
Size 53.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c85be14b618c7eaefc113d9f750a3b9b62aef9837dd20487f6ac8e3046a32118
BLAKE2b-256 checksum
How to use checksums
5039912faaa3b5e963038d8ea62adc60b53b47fa579640d909a932b5952bd4eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / workclock-0.2.0-cp311-abi3-win_amd64.whl

Download URL workclock-0.2.0-cp311-abi3-win_amd64.whl
Size 416.7 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
7cc1c8b0f0bd3ffceaef2756ea92b508e2bfc28a885472bf942d4888ddce79b6
BLAKE2b-256 checksum
How to use checksums
98137ddf2d273dd59e916e0d31e22cdc92421cc4a340f02d6255387832f375a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / workclock-0.2.0-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL workclock-0.2.0-cp311-abi3-musllinux_1_2_x86_64.whl
Size 785.6 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
dbf51198b02cff0ab594ed29c3f5d94ed56bf86e103e5854d6c40e21b1ed1370
BLAKE2b-256 checksum
How to use checksums
2fdaefbe613590f5b0816a7dbf6dd54d97896269f43c426346b6059c89a380a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / workclock-0.2.0-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL workclock-0.2.0-cp311-abi3-musllinux_1_2_aarch64.whl
Size 763.1 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
19e407a1b2989e24b54c69ba1e23c16f4b4bfc1c8316d14e88106db03ed8fe20
BLAKE2b-256 checksum
How to use checksums
227d8ee126fb26701dbfb09f52db1cb9db8202651f81bafb1f6c8c30a6979137
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / workclock-0.2.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL workclock-0.2.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 581.2 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
1115269ae08cbb40573374b92feac9d9d620846e1aa31fb27e0d7229cf933fdd
BLAKE2b-256 checksum
How to use checksums
564298919cd2b5757969dff5f933d12f008dcfedddb5cdedfe59b54965dfb39b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / workclock-0.2.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL workclock-0.2.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 584.6 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
ba451ad8650ee8703eefded373dee3bc56f5b262b5e3c8d6d84c04bd46c19f71
BLAKE2b-256 checksum
How to use checksums
62bb3efcbc7e9a98088e34865b3e74dd97810829922c1666e73a65d7bf03fad1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / workclock-0.2.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL workclock-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
Size 530.0 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b92f3edd4c62ab81fd19d9a1abeabff6b5af34cc614275a31ef817176fae55c8
BLAKE2b-256 checksum
How to use checksums
01374d0e6634495021c7500f885efa0f1933ee42cbfa5d6157d2258c7e6c4fb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / workclock-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL workclock-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 520.1 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
8ed98d7a476adeadaffeebd1cb3c5b0d467107754a95106f0b40214323329959
BLAKE2b-256 checksum
How to use checksums
59b8c1d429b5ac687e0c7c7f7c9c5994e6a16e34c21cc3995b889556063c3aa3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Security for workclock 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for workclock-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page