Advertisement
Guest User

Untitled

a guest
May 19th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. def has_intersecting_sprints(start_date: dt.date, length: int, project_id: int) -> bool:
  2.     """
  3.    Check if the new sprint has any intersections with existing sprints
  4.    :param start_date: the start date of a new sprint
  5.    :param length: the length of a new sprint
  6.    :param project_id: new sprint's project
  7.    :return:
  8.    """
  9.     sprints = Sprint.query.filter_by(is_finished=False, project_id=project_id).all()
  10.     # if we don't have any intersecting sprints then the sprint can be created
  11.     if len(sprints) == 0:
  12.         return False
  13.     # calculate the end date of a new sprint
  14.     end_date = start_date + dt.timedelta(weeks=length)
  15.     for sprint in sprints:
  16.         s_end_date = sprint.start_date + dt.timedelta(weeks=sprint.length)
  17.         # check if the sprint has any overlaps with existing sprints
  18.         has_any = (sprint.start_date <= start_date <= s_end_date or
  19.                    sprint.start_date <= end_date <= s_end_date)
  20.         if has_any:
  21.             return True
  22.     return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement