Skip to content

Instantly share code, notes, and snippets.

@pavelpy
Created April 4, 2020 14:50
Show Gist options
  • Save pavelpy/f139d388aa4d5941573f306723805aab to your computer and use it in GitHub Desktop.
Save pavelpy/f139d388aa4d5941573f306723805aab to your computer and use it in GitHub Desktop.
Check intersection of datetime ranges.
def is_dates_intersect(dt1_from, dt1_to, dt2_from, dt2_to):
"""Returns True if there is an intersection of datetime ranges."""
first_condition = (dt1_from <= dt2_from <= dt1_to)
second_condition = (dt2_from <= dt1_from <= dt2_to)
return first_condition or second_condition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment