Skip to main content

timeslot

Class for working with time slots that have an arbitrary start and end.

Completes the Python datetime module: datetime (a time), timedelta (a duration), timezone (an offset), timeslot (a range/interval).

Supports operations such as: overlaps, intersects, contains, intersection, adjacent, gap, union.

Initially developed as part of aw-core, and inspired by a similar library for .NET.

You might also be interested in pandas.Interval.

Usage

from datetime import datetime, timedelta
from timeslot import Timeslot

now = datetime.now()

slot = Timeslot(now, now + timedelta(hours=24)

assert slot.duration == timedelta(hours=24)

slot_large = Timeslot(now, now + timedelta(hours=24)
slot_small = Timeslot(now, now + timedelta(hours=1))

# The events definitely intersect
assert slot_large.intersects(slot_small)

# The larger even contains the smaller!
assert slot_large.contains(slot_small)
assert slot_small in slot_large

# You can also check if a datetime is within the slot
assert slot_large.contains(now)

# The union of a slot and a contained slot is equal to the larger slot
assert slot_large == slot_large.union(slot_small)

# Intersection
# TODO

# Gap
# TODO

# Adjacent
# TODO

Synonyms

  • timerange (the name was already taken on PyPI)
  • timeperiod (already taken on PyPI)
  • time interval

Release files for timeslot 0.1.2

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

Source distribution (sdist)

Source distribution for timeslot 0.1.2
File Size Uploaded
timeslot-0.1.2.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for timeslot 0.1.2
File Interpreter ABI Platform
timeslot-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 6.3 kB

Release files / timeslot-0.1.2.tar.gz

Download URL timeslot-0.1.2.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a2ac998657e3f3b9ca928757b4906add2c05390c5fc14ed792bb9028d08547b1
BLAKE2b-256 checksum
How to use checksums
57ab50226e1b98551c4d6af8a7764978dab67523ec6c34a38f228866bed4f1af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.5 CPython/3.9.2 Linux/5.11.13-arch1-1

Release files / timeslot-0.1.2-py3-none-any.whl

Download URL timeslot-0.1.2-py3-none-any.whl
Size 3.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f8efaec7b0a4c1e56a92ec05533219332dd9d8b577539077664c233996911b5
BLAKE2b-256 checksum
How to use checksums
7011c38eaff640ce7a4b948591bdbddc9983dabcc3438de5a898202f66cca134
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.5 CPython/3.9.2 Linux/5.11.13-arch1-1

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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