Necesito verificar si la hora actual está en rango de tiempo. El caso más sencillo TIME_END> TIME_START:¿Cómo comprobar si la hora actual está dentro del rango en python?
if time(6,0) <= now.time() <= time(12,00): print '1'
Pero los problemas comienzan cuando el usuario entra en un rango de tiempo cuando el tiempo final es menor que el tiempo de inicio, por ejemplo, "23:00 a 06:00" Un tiempo como '00: 00 'estará en este rango. Hace unos 5 años escribí esta función PHP:
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 < $tstart)
{
if ($tend - $tnow > 0 && $tnow > $tstart)
return true;
else if ($tnow - $tstart > 0 && $tnow > $tend)
return true;
else if ($tend > $tnow && $tend < $tstart && $tstart > $tnow)
return true;
else return false;
} else
{
if ($tstart < $tnow && $tend > $tnow)
return true;
else
return false;
}
ahora tengo que hacer lo mismo, pero quiero que sea guapo. Entonces, ¿qué algoritmo debería usar para determinar si la hora actual '00: 00 'está en intervalo invertido, p. ['23:00', '01:00']
?
Cortar la OP cierta holgura, que tiene sólo el 27 rep. Bajar su pregunta sin decir por qué no lo educará. –