def get_user_free_intervals(account, day, start = time(0,0,0), end = time(23,59,59)):
busy_intervals = []
weekday = day.strftime("%a")[0:2] # Get the first two characters of weekday string
tasks = account.tasks.filter(category__in=[0,3,5,6], repeat__contains=weekday, )
busy_intervals += [(task.start.time(), task.end.time()) for task in tasks]
# all_non_repeat_tasks = account.tasks.filter(category=6, start__year=day.year, start__month=day.month, start__day=day.day)
all_non_repeat_tasks = account.tasks.filter(category=6, start=day)
busy_intervals += [(task.start.time(), task.end.time()) for task in all_non_repeat_tasks]
intervals = combine(busy_intervals) # union
# compute the complement of all the intervals
free_intervals = complement(intervals, first=start, last=end)
return free_intervals
# Copied from http://nullege.com/codes/search/Intervals.complement
评论列表
文章目录