August 11th, 2004, 07:34 PM
Hi I have data in the following format
04:14 - 04:30 (00:16) other stuff
04:10 - 04:22 (00:11) other stuff
I was wondering if anyone had a nice clean way of detecting when there is over laps in the time, like the previous example... Thanks
August 11th, 2004, 10:40 PM
The easiest way i can think of to do this is to convert the times into an int using time.strptime(), and check each time to see if the time (in seconds) is greater then and or less than the other.
Sorry i cant be of any more use for the moment. But here are a few links to the modules that might be of interest; all in the standard library.
August 12th, 2004, 01:24 PM
1) parse the strings into values that can be compared, either ints as netytan suggested, or datetime objects.
2) put them into a list of tuples of (startTime, endTime), e.g.
[(start1, end1), (start2, end2),...]
3) sort the list, so that the entries are in order of their start time
4) step through the list and compare the end time of each entry with the start time of the next - if it is greater then they overlap
Dave - The Developers' Coach
for (index, (start, end)) in enumerate(timeList[:-1]):
if end > timeList[index+1]:
print 'overlapping:', start, end