Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def has_intersecting_sprints(start_date: dt.date, length: int, project_id: int) -> bool:
- """
- Check if the new sprint has any intersections with existing sprints
- :param start_date: the start date of a new sprint
- :param length: the length of a new sprint
- :param project_id: new sprint's project
- :return:
- """
- sprints = Sprint.query.filter_by(is_finished=False, project_id=project_id).all()
- # if we don't have any intersecting sprints then the sprint can be created
- if len(sprints) == 0:
- return False
- # calculate the end date of a new sprint
- end_date = start_date + dt.timedelta(weeks=length)
- for sprint in sprints:
- s_end_date = sprint.start_date + dt.timedelta(weeks=sprint.length)
- # check if the sprint has any overlaps with existing sprints
- has_any = (sprint.start_date <= start_date <= s_end_date or
- sprint.start_date <= end_date <= s_end_date)
- if has_any:
- return True
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement