Reputation: 3
I am trying to display certain strings in web app at certain UK times. This has created multiple problems, first of all making sure that the app displays these items at UK times and not just where the user is and I thought I'd sorted that out.
The problem I have is that my switch only displays the else statement and seems to be ignoring the else if. The cases work fine.
I'm sure it's something simple but I can't see it.
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>
Upvotes: 0
Views: 65
Reputation: 2694
getTimezoneOffset is a method and not a property, you need to call getTimezoneOffset()
to get the value,
var adjtime = (((new Date().getTimezoneOffset() * -1) / 60) + h);
Upvotes: 1