def get_time_for_session(task, time):
cd = datetime.date.today()
if task.cutoff == "week":
cutoff_time = datetime.datetime(cd.year, cd.month, cd.day)
cutoff_delta = datetime.timedelta(
days=datetime.datetime.weekday(cutoff_time))
cutoff_time = (cutoff_time - cutoff_delta).timestamp()
elif task.cutoff == "month":
cutoff_time = datetime.datetime(cd.year, cd.month, 1).timestamp()
qualifiers = filter(lambda t: t.started > cutoff_time, time)
time_spent_this_per = sum(map(
lambda s: s.finished - s.started, qualifiers))
return time_spent_this_per
评论列表
文章目录