javascript function to check if actual time is between opening and closing time of an event
<p>i'm working on a website where users can choose various events and add them to their timeline. Every event has an opening time and a closing time, they're saved as ints in the db as of now. 
For example an events open at 9 and closes at 18. I need a javascript function to check if the event is open when the user adds it...to make things simple let's suppose that i alwais check against the actual time.
I've got no problems to check in a normal situation (the events start at 9 and closes at 18), i'm finding some problems with events that start at 18 and end at 2 o clock. I've divided events in two classes: those where the end date is > than the starting date and those where the end date is &lt; than the starting date, but i don't know how to check in this second case!</p>

<p>Thx for your help.</p>

<p>EDIT this is the code i used and that worked for me (i was taking the date for checking from html), maybe it helps someone;</p>

<pre><code>        var dataSelezionata = $('#dataSelezionata').html();
        var dataExplode = dataSelezionata.split("/");
        var dataSelezionata = dataExplode[1]+"/"+dataExplode[0]+"/"+dataExplode[2];
        dataSelezionataJavascript = new Date(dataSelezionata);
        var oreAttuali = dataSelezionataJavascript.getHours();
        var oraInizio = parseInt($('#oraInizio').html(), 10);
        var oraFine = parseInt($('#oraFine').html(), 10);
        if (oraInizio &amp;&amp; oraFine){
            if (oraFine &gt; oraInizio){
                console.log('ora prima delle 24');
                if (!(oreAttuali &gt;= oraInizio &amp;&amp; oreAttuali &lt; oraFine)){
                    alert ("L'evento da lei selezionato non e' disponibile il giorno "+dataSelezionataJavascript.toLocaleDateString()+" alle "+dataSelezionataJavascript.toLocaleTimeString()+"");
                    return;
                }
            }
            if (oraFine &lt; oraInizio){
                console.log('ora fine dopo le 24');
                var tempoApertura = (24 - oraInizio) + oraFine;
                var dataInizio = new Date (dataSelezionataJavascript.getFullYear(), dataSelezionataJavascript.getMonth(), dataSelezionataJavascript.getDay(), oraInizio);
                var dataFine = new Date (dataSelezionataJavascript.getFullYear(), dataSelezionataJavascript.getMonth(), dataSelezionataJavascript.getDay(), oraInizio+tempoApertura);
                if (!(dataSelezionataJavascript &gt;= dataInizio &amp;&amp; dataSelezionataJavascript &lt; dataFine)){
                    alert ("L'evento da lei selezionato non e' disponibile il giorno "+dataSelezionataJavascript.toLocaleDateString()+" alle "+dataSelezionataJavascript.toLocaleTimeString()+"");
                    return;
                }
            }
        }
</code></pre>
