Я пытаюсь отобразить определенные строки в веб-приложении в определенное время в Великобритании. Это создало множество проблем, прежде всего, убедившись, что приложение отображает эти элементы во времена Великобритании, а не только там, где находится пользователь, и я подумал, что разобрался с этим.
Проблема, с которой я столкнулся, заключается в том, что Параметр switch отображает только оператор else и, похоже, игнорирует else if. Чехлы работают нормально.
Я уверен, что это что-то простое, но я не вижу этого.
window.onload = function name() {
var date = new Date();
var d = date.getUTCDay();
var t = new Date()
var h = t.getUTCHours();
var adjtime = (((new Date().getTimezoneOffset * -1) / 60) + h);
var shows = [
'String 1',
'String 2',
'String 3',
'String 4',
'String 5',
'String 6',
'String 7',
'String 8',
'String 9',
];
var currentShow;
var nextShow;
switch (d) {
case 0:
if (adjtime >= 00 && adjtime <= 02) {
currentShow = shows[0];
nextShow = shows[5];
} else if (adjtime >= 02 && adjtime <= 03) {
currentShow = shows[5];
nextShow = shows[6];
} else if (adjtime >= 03 && adjtime <= 04) {
currentShow = shows[6];
nextShow = shows[0];
} else if (adjtime >= 04 && adjtime <= 10) {
currentShow = shows[0];
nextShow = shows[3];
} else if (adjtime >= 10 && adjtime <= 11) {
currentShow = shows[3];
nextShow = shows[4];
} else if (adjtime >= 11 && adjtime <= 12) {
currentShow = shows[4];
nextShow = shows[0];
} else if (adjtime >= 12 && adjtime <= 17) {
currentShow = shows[0];
nextShow = shows[3];
} else if (adjtime >= 17 && adjtime <= 18) {
currentShow = shows[3];
nextShow = shows[0];
} else if (adjtime >= 18 && adjtime <= 20) {
currentShow = shows[0];
nextShow = shows[1];
} else if (adjtime >= 20 && adjtime <= 21) {
currentShow = shows[1];
nextShow = shows[2];
} else if (adjtime >= 21 && adjtime <= 22) {
currentShow = shows[2];
nextShow = shows[0];
} else {
currentShow = shows[0];
nextShow = shows[1];
}
break;
case 1:
if (adjtime >= 00 && adjtime <= 02) {
currentShow = shows[0];
nextShow = shows[1];
} else if (adjtime >= 02 && adjtime <= 03) {
currentShow = shows[1];
nextShow = shows[2];
} else if (adjtime >= 03 && adjtime <= 04) {
currentShow = shows[2];
nextShow = shows[0];
} else if (adjtime >= 04 && adjtime <= 10) {
currentShow = shows[0];
nextShow = shows[3];
} else if (adjtime >= 10 && adjtime <= 11) {
currentShow = shows[3];
nextShow = shows[4];
} else if (adjtime >= 11 && adjtime <= 12) {
currentShow = shows[4];
nextShow = shows[0];
} else if (adjtime >= 12 && adjtime <= 17) {
currentShow = shows[0];
nextShow = shows[3];
} else if (adjtime >= 17 && adjtime <= 18) {
currentShow = shows[3];
nextShow = shows[0];
} else if (adjtime >= 18 && adjtime <= 20) {
currentShow = shows[0];
nextShow = shows[7];
} else if (adjtime >= 20 && adjtime <= 21) {
currentShow = shows[7];
nextShow = shows[8];
} else if (adjtime >= 21 && adjtime <= 22) {
currentShow = shows[8];
nextShow = shows[0];
} else {
currentShow = shows[0];
nextShow = shows[7];
}
break;
case 2:
if (adjtime >= 00 && adjtime <= 02) {
currentShow = shows[0];
nextShow = shows[7];
} else if (adjtime >= 02 && adjtime <= 03) {
currentShow = shows[7];
nextShow = shows[8];
} else if (adjtime >= 03 && adjtime <= 04) {
currentShow = shows[8];
nextShow = shows[0];
} else if (adjtime >= 04 && adjtime <= 10) {
currentShow = shows[0];
nextShow = shows[1];
} else if (adjtime >= 10 && adjtime <= 11) {
currentShow = shows[1];
nextShow = shows[2];
} else if (adjtime >= 11 && adjtime <= 12) {
currentShow = shows[2];
nextShow = shows[0];
} else if (adjtime >= 12 && adjtime <= 17) {
currentShow = shows[0];
nextShow = shows[4];
} else if (adjtime >= 17 && adjtime <= 18) {
currentShow = shows[4];
nextShow = shows[0];
} else if (adjtime >= 18 && adjtime <= 20) {
currentShow = shows[0];
nextShow = shows[3];
} else if (adjtime >= 20 && adjtime <= 21) {
currentShow = shows[3];
nextShow = shows[4];
} else if (adjtime >= 21 && adjtime <= 22) {
currentShow = shows[4];
nextShow = shows[0];
} else {
currentShow = shows[0];
nextShow = shows[1];
}
break;
case 3:
if (adjtime >= 00 && adjtime <= 02) {
currentShow = shows[0];
nextShow = shows[3];
} else if (adjtime >= 02 && adjtime <= 03) {
currentShow = shows[3];
nextShow = shows[4];
} else if (adjtime >= 03 && adjtime <= 04) {
currentShow = shows[4];
nextShow = shows[0];
} else if (adjtime >= 04 && adjtime <= 10) {
currentShow = shows[0];
nextShow = shows[7];
} else if (adjtime >= 10 && adjtime <= 11) {
currentShow = shows[7];
nextShow = shows[8];
} else if (adjtime >= 11 && adjtime <= 12) {
currentShow = shows[8];
nextShow = shows[0];
} else if (adjtime >= 12 && adjtime <= 17) {
currentShow = shows[0];
nextShow = shows[3];
} else if (adjtime >= 17 && adjtime <= 18) {
currentShow = shows[3];
nextShow = shows[0];
} else if (adjtime >= 18 && adjtime <= 20) {
currentShow = shows[0];
nextShow = shows[1];
} else if (adjtime >= 20 && adjtime <= 21) {
currentShow = shows[1];
nextShow = shows[2];
} else if (adjtime >= 21 && adjtime <= 22) {
currentShow = shows[2];
nextShow = shows[0];
} else {
currentShow = shows[0];
nextShow = shows[1];
}
break;
case 4:
if (adjtime >= 00 && adjtime <= 02) {
currentShow = shows[0];
nextShow = shows[1];
} else if (adjtime >= 02 && adjtime <= 03) {
currentShow = shows[1];
nextShow = shows[2];
} else if (adjtime >= 03 && adjtime <= 04) {
currentShow = shows[2];
nextShow = shows[0];
} else if (adjtime >= 04 && adjtime <= 10) {
currentShow = shows[0];
nextShow = shows[3];
} else if (adjtime >= 10 && adjtime <= 11) {
currentShow = shows[3];
nextShow = shows[4];
} else if (adjtime >= 11 && adjtime <= 12) {
currentShow = shows[4];
nextShow = shows[0];
} else if (adjtime >= 12 && adjtime <= 17) {
currentShow = shows[0];
nextShow = shows[4];
} else if (adjtime >= 17 && adjtime <= 18) {
currentShow = shows[4];
nextShow = shows[0];
} else if (adjtime >= 18 && adjtime <= 20) {
currentShow = shows[0];
nextShow = shows[7];
} else if (adjtime >= 20 && adjtime <= 21) {
currentShow = shows[7];
nextShow = shows[8];
} else if (adjtime >= 21 && adjtime <= 22) {
currentShow = shows[8];
nextShow = shows[0];
} else {
currentShow = shows[0];
nextShow = shows[7];
}
break;
case 5:
if (adjtime >= 00 && adjtime <= 02) {
currentShow = shows[0];
nextShow = shows[7];
} else if (adjtime >= 02 && adjtime <= 03) {
currentShow = shows[7];
nextShow = shows[8];
} else if (adjtime >= 03 && adjtime <= 04) {
currentShow = shows[8];
nextShow = shows[0];
} else if (adjtime >= 04 && adjtime <= 10) {
currentShow = shows[0];
nextShow = shows[1];
} else if (adjtime >= 10 && adjtime <= 11) {
currentShow = shows[1];
nextShow = shows[2];
} else if (adjtime >= 11 && adjtime <= 12) {
currentShow = shows[2];
nextShow = shows[0];
} else if (adjtime >= 12 && adjtime <= 17) {
currentShow = shows[0];
nextShow = shows[3];
} else if (adjtime >= 17 && adjtime <= 18) {
currentShow = shows[3];
nextShow = shows[0];
} else if (adjtime >= 18 && adjtime <= 20) {
currentShow = shows[0];
nextShow = shows[3];
} else if (adjtime >= 20 && adjtime <= 21) {
currentShow = shows[3];
nextShow = shows[4];
} else if (adjtime >= 21 && adjtime <= 22) {
currentShow = shows[4];
nextShow = shows[0];
} else {
currentShow = shows[0];
nextShow = shows[3];
}
break;
case 6:
if (adjtime >= 00 && adjtime <= 02) {
currentShow = shows[0];
nextShow = shows[3];
} else if (adjtime >= 02 && adjtime <= 03) {
currentShow = shows[3];
nextShow = shows[4];
} else if (adjtime >= 03 && adjtime <= 04) {
currentShow = shows[4];
nextShow = shows[0];
} else if (adjtime >= 04 && adjtime <= 10) {
currentShow = shows[0];
nextShow = shows[7];
} else if (adjtime >= 10 && adjtime <= 11) {
currentShow = shows[7];
nextShow = shows[8];
} else if (adjtime >= 11 && adjtime <= 12) {
currentShow = shows[8];
nextShow = shows[0];
} else if (adjtime >= 12 && adjtime <= 17) {
currentShow = shows[0];
nextShow = shows[4];
} else if (adjtime >= 17 && adjtime <= 18) {
currentShow = shows[4];
nextShow = shows[0];
} else if (adjtime >= 18 && adjtime <= 20) {
currentShow = shows[0];
nextShow = shows[5];
} else if (adjtime >= 20 && adjtime <= 21) {
currentShow = shows[5];
nextShow = shows[6];
} else if (adjtime >= 21 && adjtime <= 22) {
currentShow = shows[6];
nextShow = shows[0];
} else {
currentShow = shows[0];
nextShow = shows[5];
}
break;
}
document.getElementById("current-show").innerHTML = currentShow;
document.getElementById("next-show").innerHTML = nextShow;
}
<p id="current-show"></p>
<p id="next-show"></p>