Skip to main content

Data type for representing time slots with a start and end.

Project description

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

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

timeslot-0.1.2.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

timeslot-0.1.2-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file timeslot-0.1.2.tar.gz.

File metadata

  • Download URL: timeslot-0.1.2.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Linux/5.11.13-arch1-1

File hashes

Hashes for timeslot-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a2ac998657e3f3b9ca928757b4906add2c05390c5fc14ed792bb9028d08547b1
MD5 4e8ad47826ff856df804556cd5fb3027
BLAKE2b-256 57ab50226e1b98551c4d6af8a7764978dab67523ec6c34a38f228866bed4f1af

See more details on using hashes here.

File details

Details for the file timeslot-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: timeslot-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.9.2 Linux/5.11.13-arch1-1

File hashes

Hashes for timeslot-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2f8efaec7b0a4c1e56a92ec05533219332dd9d8b577539077664c233996911b5
MD5 1718af95e42ad3cec466a97615eaf3e7
BLAKE2b-256 7011c38eaff640ce7a4b948591bdbddc9983dabcc3438de5a898202f66cca134

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page