def test_intersection_entire(self): now = datetime.now() tp1 = TimePeriod(now, now + timedelta(hours=1)) tp2 = TimePeriod(now - timedelta(minutes=10), now + timedelta(minutes=70)) assert tp1.intersection(tp2).duration == timedelta(minutes=60) assert tp2.intersection(tp1).duration == timedelta(minutes=60)
def test_intersection_none(): now = datetime.now() tp1 = TimePeriod(now, now + timedelta(hours=1)) tp2 = TimePeriod(now - timedelta(hours=1), now) assert tp1.intersection(tp2) is None assert tp2.intersection(tp1) is None
def test_intersection_start(): now = datetime.now() tp1 = TimePeriod(now, now + timedelta(hours=1)) tp2 = TimePeriod(now - timedelta(minutes=10), now + timedelta(minutes=50)) assert tp1.intersection(tp2).duration == timedelta(minutes=50) assert tp2.intersection(tp1).duration == timedelta(minutes=50)