DateTimeRange is a Python library to handle a time range. e.g. check whether a time is within the time range, get the intersection of time ranges, truncate a time range, iterate through a time range, and so forth.
Using the is_intersection(x, intersection_threshold=datetime.timedelta(seconds=1) function, it fails with Assertion Error if the two DateTimeRange are on different days.
from datetimerange import DateTimeRange
time_range = DateTimeRange("2015-03-22T10:00:00+0900", "2015-03-22T10:10:00+0900")
x1 = DateTimeRange("2015-03-22T10:05:00+0900", "2015-03-22T10:15:00+0900")
x2 = DateTimeRange("2015-03-23T10:05:00+0900", "2015-03-23T10:15:00+0900") # +1 day
time_range.is_intersection(x1, intersection_threshold=datetime.timedelta(seconds=1)) # No problem
time_range.is_intersection(x2, intersection_threshold=datetime.timedelta(seconds=1)) # Assertion error
The workaround (that is not pythonic or pretty):
time_range.is_intersection(x1, intersection_threshold=datetime.timedelta(seconds=1)
if time_range.is_intersection(x2): # False
time_range.is_intersection(x2, intersection_threshold=datetime.timedelta(seconds=1)
Related to issue #43
Using the
is_intersection(x, intersection_threshold=datetime.timedelta(seconds=1)
function, it fails withAssertion Error
if the two DateTimeRange are on different days.The workaround (that is not pythonic or pretty):