Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 11th, 2004, 08:34 PM
jimo9 jimo9 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 81 jimo9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 41 sec
Reputation Power: 6
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

Reply With Quote
  #2  
Old August 11th, 2004, 11:40 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 11 m 13 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
  #3  
Old August 12th, 2004, 02:24 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 9 m
Reputation Power: 265
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Overlapping times


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT