A simple solution to handle periods in time.
from datetime import datetime
from period import Period
period_1 = Period(datetime(2019, 1, 1), datetime(2019, 1, 1, 10))
period_2 = Period(datetime(2019, 1, 1, 5), datetime(2019, 1, 1, 15))
Get how much the two periods overlap. If they do not overlap it will return a negative timedelta.
period_1.get_overlap(period_2) # timedelta(hours=5)
Check if two periods overlap
period_1.has_overlap(period_2) # True
Get a new Period from the overlapping section
period_1.get_overlap_period(period_2) # Period(datetime(2019, 1, 1, 5), datetime(2019, 1, 1, 10))