0

I am using dateutils to forecast the arrival time on a journey.

  • I can represent start time as a datetime object. That's nice.

  • I can represent the journey_time as a timedelta. That's also nice

Problem: What's unclear to me is how I shall represent the meeting time so that it applies any weekday?

Considerations: If I use a datetime object, I will have to declare the meeting time for the particular date. That means that I have to update it for every day. This is rather tedious. I'd prefer a notation that allows me to say "any {MON,TUE,WED,THU,FRI,SAT,SUN}-day" at '09:00:00'

Pseudo example

import datetime
import dateutils

# setting start time as datetime object.
start = '2015-08-19T08:00:00'

# going from home to work:
mondays = 3000  # seconds as timedelta.

arrival = start + journey_time  # calculating arrival time.

# recording the first meeting...
meeting = '09:00:00'  # <--------------How should I represent this value?

arrival < meeting:   # <------------- The all important check.
# should return True, if I can make it.
root-11
  • 1,727
  • 1
  • 19
  • 33
  • Since you need to update the start value in the calculation of every day, why do you not want to update the arrival time as well? I guess ultimately you will want to sync this with some kind of calendar? Updating shouldn't be an issue then? – Dux Aug 19 '15 at 16:03

1 Answers1

0

I would suggest you represent the meeting time as a datetime.time object which has no date attributes. Expanding on your pseudocode:

import datetime

# setting start time as datetime object. 
start = datetime.datetime(2015, 8, 19, 8)

# going from home to work:
mondays = datetime.timedelta(seconds=3000)  # seconds as timedelta.

arrival = start + mondays  # calculating arrival time.

# recording the first meeting...
meeting = datetime.time(9)

if (arrival.hour*60)+arrival.minute < (meeting.hour*60)+meeting.minute:
    #code here

The if statement checks the number of minutes elapsed in the day to compare them. You could do this in seconds if required

O. Rose
  • 61
  • 1
  • 4