A simple library to deal with weekly opening hours and other recurrent weekly events
Project description
WeeklyCalendar
A simple library to deal with weekly opening hours and other recurrent weekly events
Usage
Methods will either return a Boolean or datetime based intervals.
from weekly_calendar import WeeklyCalendar from datetime import datetime, timedelta now = datetime.now() typical_week = WeeklyCalendar(resolution_in_minutes=60) # typical_week is mapped into a bitmap with a bit representing one hour assert typical_week.is_idle(now) typical_week.add_busy_interval(now, now + timedelta(hours=3)) # the date doens't really matter, only the day of the week does assert typical_week.is_busy(now) busy_intervals = typical_week.get_busy_intervals(now, now + timedelta(hours=5)) # The result is a list of intervals (start_time, end_time) idle_intervals = typical_week.get_idle_intervals(now, now + timedelta(hours=5)) # The result is a list of intervals (start_time, end_time)
You can also do union and intersection of different WeeklyCalendar
objects:
from weekly_calendar import WeeklyCalendar tw_60 = WeeklyCalendar(resolution_in_minutes=60) tw_30 = WeeklyCalendar(resolution_in_minutes=30) # resulting objects will have the lowest resolution tw_union = tw_30 + tw_60 tw_intersection = tw_30 * tw_60
You can change resolution of an existing WeeklyCalendar
object:
from weekly_calendar import WeeklyCalendar tw_60 = WeeklyCalendar(resolution_in_minutes=60) tw_60_to_30 = tw_60.copy(resolution_in_minutes=30)
Your WeeklyCalendar
object is serializable:
tw = WeeklyCalendar() str_repr = tw.dumps() tw_loaded = WeeklyCalendar.loads(str_repr) # checks equal resolution, bitmap, and extra parameters assert tw == tw_loaded
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size weekly_calendar-0.1.0-py2-none-any.whl (4.1 kB) | File type Wheel | Python version py2 | Upload date | Hashes View |
Filename, size weekly-calendar-0.1.0.tar.gz (3.8 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for weekly_calendar-0.1.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8669ebcd9f46b0cd7659bccf3ed65d21ee2a549871c3ad1ff6b7b380ea8838f3 |
|
MD5 | 654f2765f78f6cea7879e8254cfb3e75 |
|
BLAKE2-256 | 05e4d4320649995a54a0e595aa7558221858fb6ee378a3765f00663bba0efea1 |