I try to figure out how in to the code "if statement" add a specific day(official holiday dates) in month when business does not work. Now it's code works if day is Mon, Tue, Wed, Thu, Fri and time is from 09:00 to 15:00 in 24 h format. But I want in addition add holiday: For example "*if day and month is equal with 01.01 (1 January) * then will be "else" conditions.
html
<span id="date_time"></span>
<script type="text/javascript">window.onload = date_time('date_time');</script>
Script
function date_time(id)
{
date = new Date;
year = date.getFullYear();
month = date.getMonth();
months = new Array('Janvāris', 'Februāris', 'Marts', 'Aprīlis', 'Maijs', 'Jūnījs', 'Jūlījs', 'Augusts', 'Septembris', 'Oktobris', 'Novembris', 'Decembris');
d = date.getDate();
day = date.getDay();
days = new Array('Svētdiena', 'Pirmdiena', 'Otrdiena', 'Trešdiena', 'Ceturtdiena ', 'Piektdiena', 'Sestdiena');
h = date.getHours();
if(h<10)
{
h = "0"+h;
}
m = date.getMinutes();
if(m<10)
{
m = "0"+m;
}
s = date.getSeconds();
if(s<10)
{
s = "0"+s;
}
if ((day == 1 || day == 2 || day == 3 || day == 4 || day == 5 ) && h >= 9 && h <= 14) {
result = 'Ir '+days[day]+' '+year+'.'+d+'.'+months[month]+' '+h+':'+m+':'+s+' ēdnīca ir atvērta!' ;
document.getElementById("date_time").style.backgroundColor = '#27ae60';
} else {
result = 'Ir '+days[day]+' '+year+'.'+d+'.'+months[month]+' '+h+':'+m+':'+s+' ēdnīca ir slēgta!' ;
document.getElementById("date_time").style.backgroundColor = 'rgba(231, 76, 60, 0.85)';
}
////////////
var now=new Date();
var weekday=new Array(7);
weekday[0]="Svētdiena";
weekday[1]="Pirmdiena";
weekday[2]="Otrdiena";
weekday[3]="Trešdiena";
weekday[4]="Ceturtdiena";
weekday[5]="Piektdiena";
weekday[6]="Sestdiena";
var checkTime=function(){
var today=weekday[now.getDay()];
var timeDiv=document.getElementById('timeDiv');
var dayOfWeek=now.getDay();
var hour=now.getHours();
var minutes=now.getMinutes();
var suffix=hour>=24?"":"";
if(minutes<10){minutes="0"+minutes;
}
if((dayOfWeek==1||dayOfWeek==2||dayOfWeek==3||dayOfWeek==4||dayOfWeek==5)&&hour>=9&&hour<=14)
{
timeDiv.innerHTML='Ir '+today+' '+hour+':'+minutes+suffix+' - ēdnīca "Līdaciņa" ir atvērta!';timeDiv.className='atverts';
}else{
timeDiv.innerHTML='Ir '+today+' '+hour+':'+minutes+suffix+' - ēdnīca "Līdaciņa" ir slēgta!';timeDiv.className='aizverts';
}
};
var currentDay=weekday[now.getDay()];
var currentDayID="#"+currentDay;
$(currentDayID).toggleClass("today");setInterval(checkTime,1000);checkTime();
P.S I have this error TypeError: timeDiv is null
Aucun commentaire:
Enregistrer un commentaire