Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Set operations for calendar intervals

License

Notifications You must be signed in to change notification settings

ashenfad/calgebra

Repository files navigation

calgebra πŸ—“οΈ

Set algebra for calendars. Compose lazily and query efficiently.

Installation

pip install calgebra
# Or with Google Calendar support
pip install calgebra[google-calendar]
# Or with iCalendar (.ics) file support
pip install calgebra[ical]

Quick Start

from calgebra import day_of_week, time_of_day, at_tz, pprint, hours, HOUR
from itertools import islice
tz = "US/Pacific"
at = at_tz(tz)
# Team calendars
alice, bob, charlie = ... # Timeline objects (Google Calendar, .ics files, etc.)
# Define when work happens
weekend = day_of_week(["saturday", "sunday"], tz=tz)
weekdays = ~weekend
workhours = time_of_day(start=9*HOUR, duration=8*HOUR, tz=tz)
business_hours = weekdays & workhours
# When is anyone busy?
team_busy = alice | bob | charlie
# Free slots: business hours minus busy, at least 2 hours
free_slots = (business_hours - team_busy) & (hours >= 2)
# Query January 2025
pprint(islice(free_slots[at("2025-01-01"):at("2025-02-01")], 5), tz=tz)
# 2025εΉ΄01月06ζ—₯ 14:00:00 -> 2025εΉ΄01月06ζ—₯ 17:00:00
# 2025εΉ΄01月08ζ—₯ 09:00:00 -> 2025εΉ΄01月08ζ—₯ 12:00:00
# ...

Core Features:

  • Set operations: | (union), & (intersection), - (difference), ~ (complement)
  • Lazy composition: Build complex queries, execute with slicing
  • Recurring patterns: day_of_week(), time_of_day(), recurring() (RFC 5545)
  • Interval filtering: hours >= 2, summary == "standup", custom properties
  • Google Calendar: Read/write via calgebra.gcsa
  • iCalendar (.ics): Load/save standard RFC 5545 files

β†’ Quick-start | Tutorial | API Reference | Google Calendar | Demo Video

License

MIT License - see LICENSE file for details.

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /