My question is similar to Efficient date range overlap calculation in python?, however, I need to calculate the overlap with a full timestamp and not days, but more importantly, I cannot specify a specific date as the overlap, rather only hours.
import pandas as pd
import numpy as np
df = pd.DataFrame({'first_ts': {0: np.datetime64('2020-01-25 07:30:25.435000'),
1: np.datetime64('2020-01-25 07:25:00')},
'last_ts': {0: np.datetime64('2020-01-25 07:30:25.718000'),
1: np.datetime64('2020-01-25 07:25:00')}})
df['start_hour'] = 7
df['start_minute'] = 0
df['end_hour'] = 8
df['end_minute'] = 0
display(df)
How can I calculate the overlap duration of the interval (first_ts, last_ts) with the second interval in milliseconds? Potentially, I would need to construct a timestamp on each day with the interval defined by the hours and then calculate the overlap.