This is a quite simple implementation.
EDIT: this is with timezone, but I'm not 100% sure it works as it should. Timezones can be tricky.
<script>
var currentIndex = 0; // global var. If the reporter index is different than this, the change will be triggered.
var serverTimezone = -4 // New York Timezone. notice DST. In Winter time this should be -5.
// all on New York Time
var reporters = [
{name: 'Tintin', time: '2017-07-19 08:00:00', url: 'http://photos1.blogger.com/img/28/3438/320/Tintin.jpg'},
{name: 'Kent Brockman', time: '2017-07-19 09:00:00', url: 'https://static.simpsonswiki.com/images/thumb/1/16/Kent_Brockman.png/250px-Kent_Brockman.png'},
{name: 'Clark Kent', time: '2017-07-19 11:00:00', url: 'https://i.ytimg.com/vi/9HbXdHu3NaI/hqdefault.jpg'},
{name: 'Peter Parker', time: '2017-07-19 13:00:00', url: 'http://sotd.us/justingabrie/peterparker/Module08/images/peterparker.jpg'}
];
function getReporter() {
var index = 0;
var now = new Date();
var clientTimezone = -1 * now.getTimezoneOffset() / 60; // this returns (in Summer time) example: for Brussels: 2 , NYC: -4, ...
var timezoneOffset = serverTimezone - clientTimezone;
for(var i=0; i< reporters.length; i++) {
var reporter_time = parseDatetimeString(reporters[i].time, timezoneOffset);
if(now >= reporter_time) {
index = i;
}
}
if(currentIndex != index) {
changeReporter(index);
}
}
function changeReporter(index) {
currentIndex = index;
document.getElementById('banner').src = reporters[index].url;
}
function parseDatetimeString(s, timezoneOffset) {
if(! timezoneOffset) {
timezoneOffset = 0;
}
var bits = s.split(/\D/);
return new Date(bits[0], --bits[1], bits[2], Number(bits[3]) - timezoneOffset, bits[4], bits[5]);
}
window.onload = function() {
getReporter();
// check every 20 sec, feel free to change this value,
// it isn't harmful to the client so set it even smaller
setInterval(getReporter, 20000);
}
</script>
<img id="banner"/>
Timezones are not included yet; Which timezone are you on? There is some work to handle this.
(I'm on Kent Brockman now, 14:00:00h on Brussels time; but presumably you have clients in other timezones...)
<script>
var currentIndex = 0; // global var. If the reporter index is different than this, the change will be triggered.
var reporters = [
{name: 'Tintin', time: '2017-07-19 13:00:00', url: 'http://photos1.blogger.com/img/28/3438/320/Tintin.jpg'},
{name: 'Kent Brockman', time: '2017-07-19 14:00:00', url: 'https://static.simpsonswiki.com/images/thumb/1/16/Kent_Brockman.png/250px-Kent_Brockman.png'},
{name: 'Clark Kent', time: '2017-07-19 15:00:00', url: 'https://i.ytimg.com/vi/9HbXdHu3NaI/hqdefault.jpg'},
{name: 'Peter Parker', time: '2017-07-19 16:00:00', url: 'http://sotd.us/justingabrie/peterparker/Module08/images/peterparker.jpg'}
];
function getReporter() {
var index = 0;
var now = new Date();
for(var i=0; i< reporters.length; i++) {
var reporter_time = parseDatetimeString(reporters[i].time);
if(now >= reporter_time) {
index = i;
}
}
if(currentIndex != index) {
changeReporter(index);
}
}
function changeReporter(index) {
currentIndex = index;
document.getElementById('banner').src = reporters[index].url;
}
function parseDatetimeString(s) {
var bits = s.split(/\D/);
return new Date(bits[0], --bits[1], bits[2], bits[3], bits[4]);
}
window.onload = function() {
getReporter();
// check every 20 sec, feel free to change this value,
// it isn't harmful to the client to set it even smaller
setInterval(getReporter, 20000);
}
</script>
<img id="banner"/>