title: How to check if the current time is in range in python?
body: <p>I need to check if the current time is in timerange. The most simple case time_end > time_start:</p>
  
  <pre><code>if time(6,0) &lt;= now.time() &lt;= time(12,00): print '1'
  </code></pre>
  
  <p>But troubles begin when user enters a time range when the end time is smaller than the start time, e.g. "23:00 - 06:00". A time like '00:00' will be in this range. About 5 years ago I wrote this PHP function:</p>
  
  <pre><code>function checkInterval($start, $end)
    {    
      $dt = date("H:i:s");    
  
      $tstart = explode(":", $start);
      $tend =   explode(":", $end);
      $tnow =   explode(":", $dt);
  
      if (!$tstart[2])
        $tstart[2] = 0;
  
      if (!$tend[2])
        $tend[2] = 0;  
  
      $tstart = $tstart[0]*60*60 + $tstart[1]*60 + $tstart[2];
      $tend   = $tend[0]*60*60   + $tend[1]*60   + $tend[2];
      $tnow   = $tnow[0]*60*60   + $tnow[1]*60   + $tnow[2];
  
      if ($tend &lt; $tstart)
        {
          if ($tend - $tnow &gt; 0 &amp;&amp; $tnow &gt; $tstart)
            return true;
          else if ($tnow - $tstart &gt; 0 &amp;&amp; $tnow &gt; $tend)
            return true;
          else if ($tend &gt; $tnow &amp;&amp; $tend &lt; $tstart &amp;&amp; $tstart &gt; $tnow)
            return true;
          else return false;
        } else
        {
          if ($tstart &lt; $tnow &amp;&amp; $tend &gt; $tnow)
            return true;
          else
            return false;
        }
  </code></pre>
  
  <p>Now I need to do the same thing, but I want to make it good looking. So, what algorithm should I use to determine if the current time '00:00' is in <em>reversed</em> range e.g. <code>['23:00', '01:00']</code>?</p>