python - Using datetime and dateutils to calculate a journey -
i using dateutils forecast arrival time on journey.
i can represent start time datetime object. that's nice.
i can represent journey_time timedelta. that's nice
problem: what's unclear me how shall represent meeting time applies weekday?
considerations: if use datetime object, have declare meeting time particular date. means have update every day. rather tedious. i'd prefer notation allows me "any {mon,tue,wed,thu,fri,sat,sun}-day" @ '09:00:00'
pseudo example
import datetime import dateutils # setting start time datetime object. start = '2015-08-19t08:00:00' # going home work: mondays = 3000 # seconds timedelta. arrival = start + journey_time # calculating arrival time. # recording first meeting... meeting = '09:00:00' # <--------------how should represent value? arrival < meeting: # <------------- important check. # should return true, if can make it.
i suggest represent meeting time datetime.time object has no date attributes. expanding on pseudocode:
import datetime # setting start time datetime object. start = datetime.datetime(2015, 8, 19, 8) # going home work: mondays = datetime.timedelta(seconds=3000) # seconds timedelta. arrival = start + mondays # calculating arrival time. # recording first meeting... meeting = datetime.time(9) if (arrival.hour*60)+arrival.minute < (meeting.hour*60)+meeting.minute: #code here
the if statement checks number of minutes elapsed in day compare them. in seconds if required
Comments
Post a Comment