script.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:ClassGotcha-Backend 作者: ClassGotcha 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号