yeti_c,
The following code is a "quick" and "not well test" clock fix.
Please let me know about your tests.
PS1: The "ctag" is some marks that I create just for you location on the code;
PS2: There is more to be done...
mfontolan
Lets do it again...
ctag1 - Display Clock Formated (Remaing timing and deadline hour)
- Code: Select all
// ctag1
function zslash(svalue, iwidth)
{
var szero = String(svalue);
var ch = szero.substr(0,1);
while (ch == ' ')
{
szero = szero.substr(1, szero.length);
ch = szero.substr(0,1);
}
ch = szero.substr(szero.length - 1, szero.length);
while (ch == ' ')
{
szero = szero.substr(0, szero.length - 1);
ch = szero.substr(szero.length - 1, szero.length);
}
var i=0;
for (i=0; i < (iwidth - szero.length); i++)
{
szero = '0' + szero;
}
return szero;
}
function countDown()
{
var clock = document.getElementById('clock');
--seconds1;
if(seconds1 < 0 ){
--minutes1;
if( minutes1 < 0 ){
--hours1;
if( hours1 < 0 ){
hours1 = 0;
if( minutes1 <= 0 && seconds1 <= 0 ){
clearInterval(clockInterval);//No more counting down
//No weird negative #s
minutes1= 0;
seconds1 = 0;
return;
}
}
minutes1 = 59;
}
seconds1 = 59;
}
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var day = ' @ ';
var ampm = '';
minutes = (minutes + minutes1);
if (minutes >= 60) {
hours = hours + 1;
minutes = minutes - 60;
}
hours = (hours + hours1);
if (hours >= 24)
{
day = "tomorrow @ ";
hours = hours - 24
}
else
{
day = "today @ ";
}
if (clockFormat == "am/pm") {
ampm = " am";
if (hours >= 12)
{
ampm = " pm";
hours = hours - 12;
}
if (hours == 0) hours = 12;
}
if (clockFormat !="Off") {
clock.innerHTML = zslash(hours1, 2) + 'hrs ' + zslash(minutes1, 2) + 'min ' + zslash(seconds1, 2) + 'sec [' + day + "<b>" + zslash(hours, 2) + ":" + zslash(minutes, 2) + ampm + "</b>]"
}
else
{
clock.innerHTML = ""
}
}
ctag2 - Create a var to store clockFormat
- Code: Select all
var timeWIDTH = 18;
var clock;
var clockInterval;
// ctag2
var clockFormat;
var hours1;
var minutes1;
var seconds1;
ctag3 - Start Clock
- Code: Select all
// ctag3
// ---- Start Clock ----
tmp = rightside.innerHTML.indexOf(timeLocStr);//to make sure there is a clock.
if( tmp > -1 ){
timeLoc = tmp + timeLocStr.length ;
tmp = rightside.innerHTML;
timeStr = tmp.substring(timeLoc,timeLoc + timeWIDTH);
time = timeStr.split(/\n|hrs\n|min\n|sec/);
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var day = ' @ ';
var ampm = ' ';
clockFormat = OPTIONS['24hourClockFormat'];
if (time[1][0] == '0')
{
time[1] = time[1][1];
}
hours1 = parseInt(time[1]);
minutes1 = parseInt(time[2]);
seconds1 = parseInt(time[3]);
clockInterval = window.setInterval(countDown,1000);
}
ctag4 - reinitClock
- Code: Select all
// ctag4
function reinitClock()
{
var response = unsafeWindow.request.responseText.split("&");
timeStr = response[2];
time = timeStr.split(/hrs|min|sec/);
if (time[0][0] == '0')
{
time[0] = time[0][1];
}
hours1 = parseInt(time[0]);
minutes1 = parseInt(time[1]);
seconds1 = parseInt(time[2]);
}
ctag5 - Change Clock Format
- Code: Select all
// ctag5
function toggle24HourClock()
{
if (OPTIONS["24hourClockFormat"] == "Off")
{
OPTIONS["24hourClockFormat"] = "am/pm";
}
else if (OPTIONS["24hourClockFormat"] == "am/pm")
{
OPTIONS["24hourClockFormat"] = "24h";
}
else
{
OPTIONS["24hourClockFormat"] = "Off";
}
serialize("OPTIONS", OPTIONS);
this.innerHTML = "Clock Format: <b> " + OPTIONS["24hourClockFormat"] + '</b>';
clockFormat = myOptions["24hourClockFormat"];
}
Brazil #3 @ Agu, 2007.