Skip to content

Instantly share code, notes, and snippets.

@pavelpy
pavelpy / is_dates_intersect.py
Created April 4, 2020 14:50
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