title: checking whether current time is between time range
body: <p>I am writing a python app where I only want processing to occur between a certain time range which is specified as parameters.</p>
  
  <p>e.g. if the user provides parameters 9:00am 10:00pm, then the processing will only happen between that range.</p>
  
  <p>The code below seems to achieve what I want however I am unsure how to handle the case where the start time is e.g. 11:00pm and end time is 08:00am. In this case 8am would refer to the next day however the code below wouldn't handle that.</p>
  
  <p>Any advice?
  Thanks</p>
  
  <pre><code>    now = datetime.now()
      now_time = now.time()
  
      if now_time &gt;= args.start and now_time &lt;= args.end:
          # Process as normal
      else:
          # Sleep until start time
          dt_now = timedelta(hours=now_time.hour, minutes = now_time.minute, seconds=now_time.second, microseconds=now_time.microsecond)
          dt_start = timedelta(hours=args.start.hour, minutes = args.start.minute, seconds=args.start.second, microseconds=args.start.microsecond)
          time_to_wait = abs((dt_start - dt_now).seconds)
          time.sleep(time_to_wait)
  </code></pre>