Closed tgsimo92 closed 3 years ago
@tgsimo92
You can call intersection
method combined with functools.reduce
method.
For example:
from functools import reduce
from datetimerange import DateTimeRange
ranges = [
DateTimeRange("2021-01-01T10:00:00+0900", "2021-01-01T10:10:00+0900"),
DateTimeRange("2021-01-01T10:01:00+0900", "2021-01-01T10:10:00+0900"),
DateTimeRange("2021-01-01T10:00:00+0900", "2021-01-01T10:09:00+0900"),
]
print(reduce(lambda lhs, rhs: lhs.intersection(rhs), ranges))
2021-01-01T10:01:00+0900 - 2021-01-01T10:09:00+0900
How can i intersect multiple date time range?