Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def _rangesOverlap(start1, end1, start2, end2):
"""
Check if [start1, end1) and [start2, end2) overlap.
@type start1: L{datetime.datetime}
@type end1: L{datetime.datetime}
@type start2: L{datetime.datetime}
@type end2: L{datetime.datetime}
@rtype: L{bool}
"""
# This is not very good, because we can't handle dates outside of these
# bounds, but hopefully that will never be a practical problem.
_DATE_MIN = Time.fromDatetime(datetime(1, 1, 1, 0, 0, 0))
_DATE_MAX = Time.fromDatetime(datetime(9999, 1, 1, 0, 0, 0))
if start1 is None:
start1 = _DATE_MIN
if start2 is None:
start2 = _DATE_MIN
if end1 is None:
end1 = _DATE_MAX
if end2 is None:
end2 = _DATE_MAX
return (start1 <= start2 < end1) or (start2 <= start1 < end2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment