paul@48 | 1 | #!/usr/bin/env python |
paul@48 | 2 | |
paul@48 | 3 | from bisect import bisect_left, insort_left |
paul@48 | 4 | |
paul@48 | 5 | # Time management. |
paul@48 | 6 | |
paul@48 | 7 | def insert_period(freebusy, period): |
paul@48 | 8 | insort_left(freebusy, period) |
paul@48 | 9 | |
paul@48 | 10 | def remove_period(freebusy, uid): |
paul@48 | 11 | i = 0 |
paul@48 | 12 | while i < len(freebusy): |
paul@48 | 13 | t = freebusy[i] |
paul@48 | 14 | if len(t) >= 3 and t[2] == uid: |
paul@48 | 15 | del freebusy[i] |
paul@48 | 16 | else: |
paul@48 | 17 | i += 1 |
paul@48 | 18 | |
paul@48 | 19 | def period_overlaps(freebusy, period): |
paul@48 | 20 | dtstart, dtend = period[:2] |
paul@48 | 21 | i = bisect_left(freebusy, (dtstart, dtend, None)) |
paul@48 | 22 | return ( |
paul@48 | 23 | i < len(freebusy) and (dtend is None or freebusy[i][0] < dtend) |
paul@48 | 24 | or |
paul@48 | 25 | i > 0 and freebusy[i - 1][1] > dtstart |
paul@48 | 26 | ) |
paul@48 | 27 | |
paul@48 | 28 | # vim: tabstop=4 expandtab shiftwidth=4 |