#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    81
    Rep Power
    12

    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. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    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

IMN logo majestic logo threadwatch logo seochat tools logo