// Javascript from Moodle modules // gslis irc chat javascript routines var gslistimeoffset; function ampmtime(rHours, rMins) { // convert 24 hour notation to U.S. notation var ampm = "am"; if (rHours == 0) rHours = 12; if (rHours > 11) ampm = "pm"; if (rHours > 12) rHours -= 12; return (rHours + ":" + padint(rMins) + " " + ampm); } function padint(val) { // pads any integer up to 99 with leading zeros return val = (val < 10) ? '0' + val : val; } function startClock(basetime) { // the basetime comes from php, which is in seconds... js uses milliseconds basetime=basetime * 1000; // get the current time, in epoch format var now = new Date(); var currenttime = now.getTime(); // stash the offset... we'll use that every update to tweak our local time gslistimeoffset = basetime - currenttime; updateClock(); } function returnObjById( id ) { if (document.getElementById) var returnVar = document.getElementById(id); else if (document.all) var returnVar = document.all[id]; else if (document.layers) var returnVar = document.layers[id]; return returnVar; } function updateClock() { /// get the current time, in epoch format var now = new Date(); var currenttime = now.getTime(); // use the known offset, and the local browser time, to fix up the local time var truetime = new Date(currenttime + gslistimeoffset); returnObjById('clockid').value=ampmtime(truetime.getHours(), truetime.getMinutes()); // set a timer to update again every second setTimeout("updateClock()", 1000); }