i have an if statement to change time back to 12 after it hits 11:45:
i = (i >= 192) ? i - 192 : ( i >= 96) ? i - 96 : i
var mins = (i * 15 % 60)
var hours = Math.floor(i * 15 / 60)
var ampm = (hours >= 12) ? "PM" : "AM"
hours = (hours == 0) ? 12 : (hours >= 12) ? hours - 12 : hours;
var nextMins, nextHours = hours;
switch (mins) {
case 0:
mins = "";
nextMins = 15;
break;
case 45:
nextMins = "";
nextHours = hours+1;
break;
default:
nextMins = mins + 15;
break;
}
var time = hours + (mins == "" ? "" : ":" + mins) + " - " + nextHours + (nextMins == "" ? "" : ":" + nextMins) + ampm
it changes in 15 minute intervals, the issue is it will start at 12 but after it gets to 12:00 again it will display as 0:15, 0:30, 0:45. Instead of 12:15, 12:30, 12:45
I thought this part of the if statement would do it:
hours = (hours == 0) ? 12
but isn’t working?
The simplest way is probably
This way copes with any positive integer for hours (eg. 36 will still return 12).