|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Overlapping times
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 |
|
#2
|
||||
|
||||
|
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. http://www.python.org/doc/2.3.4/lib/module-time.html http://www.python.org/doc/2.3.4/lib/module-datetime.html http://www.python.org/doc/2.3.4/lib/module-calendar.html Mark. |
|
#3
|
|||
|
|||
|
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 Code:
for (index, (start, end)) in enumerate(timeList[:-1]):
if end > timeList[index+1][0]:
print 'overlapping:', start, end
Dave - The Developers' Coach |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Overlapping times |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|