I have a list of DateTime objects, and I want to compare if any two of them has the same Hour and Minutes or at most 2 minutes apart. I compare them by using the itertools.combinations( data, 2 )
. But I am stuck in the comparison part. I am not sure how to compare 2 minutes or more because if one timestamp is 11:58 two minutes more will be 12:00, which means I can add 2 to 11:58 as it will go to 11:60 instead of 12:00.
I converted the dateTime objects to string with this
dt1 = int((acqList[a].timestamp).time().strftime('%H%M'))
dt2 = int((acqList[b].timestamp).time().strftime('%H%M'))
Then, I did this
if dt1 == dt2 or dt1+1 == dt2 or dt2+1 == dt1 or dt1-1 == dt2 or dt2-1 == dt1:
but this will lead to the concern of 1160 and did not include at most 2 minutes difference
example of the dateTime object List:
2019-10-01 15:37:11+00:00
2019-10-01 15:37:09+00:00
2019-10-01 16:09:06+00:00
2019-10-01 15:24:55+00:00
2019-10-01 16:36:56+00:00
2019-10-01 10:08:39+00:00