The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> World Clock .. glitch ?
AJ Knight
post Aug 19 2007, 01:04 AM
Post #1





Group: Members
Posts: 3
Joined: 19-August 07
Member No.: 3,584



Hey People

I have this world clock that displys 25 different time zones, and the local system time ... but for some reason ... when ever the system time goes into the am .. most of the other times go weird ...

Here is my code

head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>World Time</title>
<!-- Dull Image -->
<script language="JavaScript1.2">
<!--
function makevisible(cur,which){
if (which==0)
cur.filters.alpha.opacity=75
else
cur.filters.alpha.opacity=100
}
window.resizeTo(550,700)


//-->
</script>
<script language="JavaScript"><!--


<!-- Begin

function GetTime() {
var dt = new Date();
var def = dt.getTimezoneOffset()/60;
var gmt = (dt.getHours() + def);
document.clock.local.value = (IfZero(dt.getHours()) + ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds()));
var ending = ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds());
var rome =check24(((gmt + 1) > 24) ? ((gmt + 1)): (gmt + 1));
document.clock.rome.value = (IfZero(rome) + ending);
var isr =check24(((gmt + 2) > 24) ? ((gmt + 2) - 24) : (gmt + 2));
document.clock.Israel.value = (IfZero(isr) + ending);
var msw =check24(((gmt + 3) > 24) ? ((gmt + 3) - 24) : (gmt + 3));
document.clock.msw.value = (IfZero(msw) + ending);
var baku =check24(((gmt + 4) > 24) ? ((gmt + 4) - 24) : (gmt + 4));
document.clock.baku.value = (IfZero(baku) + ending);
var del =check24(((gmt + 5) > 24) ? ((gmt + 5) - 24) : (gmt + 5));
document.clock.del.value = (IfZero(del) + ending);
var dh =check24(((gmt + 6) > 24) ? ((gmt + 6) - 24) : (gmt + 6));
document.clock.dh.value = (IfZero(dh) + ending);
var kok =check24(((gmt +7 ) > 24) ? ((gmt +7 ) - 24) : (gmt + 7));
document.clock.kok.value = (IfZero(kok) + ending);
var ho =check24(((gmt + 8) > 24) ? ((gmt + 8) - 24) : (gmt + 8));
document.clock.ho.value = (IfZero(ho) + ending);
var tky =check24(((gmt + 9) > 24) ? ((gmt + 9) - 24) : (gmt + 9));
document.clock.tky.value = (IfZero(tky) + ending);
var sdn =check24(((gmt + 10) > 24) ? ((gmt + 10) - 24) : (gmt + 10));
document.clock.sdn.value = (IfZero(sdn) + ending);
var mag =check24(((gmt + 11) > 24) ? ((gmt + 11) - 24) : (gmt + 11));
document.clock.mag.value = (IfZero(mag) + ending);
var wll =check24(((gmt + 12) > 24) ? ((gmt + 12) - 24) : (gmt + 12));
document.clock.wll.value = (IfZero(wll) + ending);

var _GMT =check24(((gmt)) ? ((gmt)) : (gmt));

document.clock._GMT.value = (IfZero(_GMT) + ":" + IfZero(dt.getMinutes()) + ":" + IfZero(dt.getSeconds()));
var eniw =check24(((gmt + (24-12)) > 24) ? ((gmt + (24-12)) - 24) : (gmt + (24-12)));
document.clock.eniw.value = (IfZero(eniw) + ending);
var sam =check24(((gmt + (24-11)) > 24) ? ((gmt + (24-11)) - 24) : (gmt + (24-11)));
document.clock.sam.value = (IfZero(sam) + ending);
var haw =check24(((gmt + (24-10)) > 24) ? ((gmt + (24-10)) - 24) : (gmt + (24-10)));
document.clock.Hawaii.value = (IfZero(haw) + ending);
var ala =check24(((gmt + (24-9)) > 24) ? ((gmt + (24-9)) - 24) : (gmt + (24-9)));
document.clock.alaska.value = (IfZero(ala) + ending);
var pacif =check24(((gmt + (24-8)) >= 24) ? ((gmt + (24-8)) - 24) : (gmt + (24-8)));
document.clock.pacif.value = (IfZero(pacif) + ending);
var mount =check24(((gmt + (24-7)) > 24) ? ((gmt + (24-7)) - 24) : (gmt + (24-7)));
document.clock.mount.value = (IfZero(mount) + ending);
var center =check24(((gmt + (24-6)) > 24) ? ((gmt + (24-6)) - 24) : (gmt + (24-6)));
document.clock.center.value = (IfZero(center) + ending);
var east =check24(((gmt + (24-5)) > 24) ? ((gmt + (24-5)) - 24) : (gmt + (24-5)));
document.clock.east.value = (IfZero(east) + ending);
var atl =check24(((gmt + (24-4)) > 24) ? ((gmt + (24-4)) - 24) : (gmt + (24-4)));
document.clock.atl.value = (IfZero(atl) + ending);
var bra =check24(((gmt + (24-3)) > 24) ? ((gmt + (24-3)) - 24) : (gmt + (24-3)));
bra = (bra >= 24) ? bra - 24 : bra;
document.clock.bra.value = (IfZero(bra) + ending);
var mid =check24(((gmt + (24-2)) > 24) ? ((gmt + (24-2)) - 24) : (gmt + (24-2)));
mid = (mid >= 24) ? mid - 24 : mid;
document.clock.mid.value = (IfZero(mid) + ending);
var azo =check24(((gmt + (24-1)) > 24) ? ((gmt + (24-1)) - 24) : (gmt + (24-1)));
azo = (azo >= 24) ? azo - 24 : azo;
document.clock.azo.value = (IfZero(azo) + ending);
setTimeout("GetTime()", 1000);
}
function IfZero(num) {
return ((num <= 9) ? ("0" + num) : num);
}
function check24(hour) {
return (hour >= 24) ? hour - 24 : hour;
}

// -->
</script>
</head>


<body bgcolor="#6666" onload="java script:GetTime();">



<center><br>

<h2><b>WORLD CLOCK</b></h2>
<p>
<form name="clock">
<strong>Your Local Time Is: <input type="text" size="8" name="local"></strong></p>
<p>
<table border="0" cellpadding="0" cellspacing="2" width="326">
<tr>
<td width="170" nowrap>
<div align="right">
Eniwetok (GMT-12)</div>
</td>
<td><input type="text" size="8" name="eniw"></td>
<td width="50"></td>
<td width="170" nowrap>
<div align="right">
Central Time (GMT-6)</div>
</td>
<td><input type="text" size="8" name="center"></td>
</tr>
<tr>
<td width="170">
<div align="right">
Samoa (GMT-11)</div>
</td>
<td><input type="text" size="8" name="sam"></td>
<td width="50"></td>
<td width="170">
<div align="right">
Eastern Time (GMT-5)</div>
</td>
<td><input type="text" size="8" name="east"></td>
</tr>
<tr>
<td width="170">
<div align="right">
Hawaii (GMT-10)</div>
</td>
<td><input type="text" size="8" name="Hawaii"></td>
<td width="50"></td>
<td width="170">
<div align="right">
Atlantic Time (GMT-4)</div>
</td>
<td><input type="text" size="8" name="atl"></td>
</tr>
<tr>
<td width="170">
<div align="right">
Alaska (GMT-9)</div>
</td>
<td><input type="text" size="8" name="alaska"></td>
<td width="50"></td>
<td width="170">
<div align="right">
Brazilia (GMT-3)</div>
</td>
<td><input type="text" size="8" name="bra"></td>
</tr>
<tr>
<td width="170">
<div align="right">
Pacific Time (GMT-8)</div>
</td>
<td><input type="text" size="8" name="pacif"></td>
<td width="50"></td>
<td width="170">
<div align="right">
Mid-Atlantic (GMT-2)</div>
</td>
<td><input type="text" size="8" name="mid"></td>
</tr>
<tr>
<td width="170">
<div align="right">
Mountain Time (GMT-7)</div>
</td>
<td><input type="text" size="8" name="mount"></td>
<td width="50"></td>
<td width="170">
<div align="right">
Azores (GMT-1)</div>
</td>
<td><input type="text" size="8" name="azo"></td>
</tr>
</table>
</p>
<p><strong>Greenwich Mean Time (GMT) <input type="text" size="8" name="_GMT"></strong></p>
<p>
<table border="0" cellpadding="0" cellspacing="2" width="326">
<tr>
<td width="170" nowrap>
<div align="right">
Rome (GMT +1)</div>
</td>
<td><input type="text" size="8" name="rome"></td>
<td width="50"></td>
<td width="170">
<div align="right">
Bangkok (GMT +7)</div>
</td>
<td><input type="text" size="8" name="kok"></td>
</tr>
<tr>
<td width="170">
<div align="right">
Israel (GMT +2)</div>
</td>
<td><input type="text" size="8" name="Israel"></td>
<td width="50"></td>
<td width="170" nowrap>
<div align="right">
Hong Kong (GMT +8)</div>
</td>
<td><input type="text" size="8" name="ho"></td>
</tr>
<tr>
<td width="170">
<div align="right">
Moscow (GMT +3)</div>
</td>
<td><input type="text" size="8" name="msw"></td>
<td width="50"></td>
<td width="170">
<div align="right">
Tokyo (GMT +9)</div>
</td>
<td><input type="text" size="8" name="tky"></td>
</tr>
<tr>
<td width="170">
<div align="right">
Baku (GMT +4)</div>
</td>
<td><input type="text" size="8" name="baku"></td>
<td width="50"></td>
<td width="170">
<div align="right">
Sydney (GMT +10)</div>
</td>
<td><input type="text" size="8" name="sdn"></td>
</tr>
<tr>
<td width="170">
<div align="right">
New Delhi (GMT +5)</div>
</td>
<td><input type="text" size="8" name="del"></td>
<td width="50"></td>
<td width="170">
<div align="right">
Magadan (GMT +11)</div>
</td>
<td><input type="text" size="8" name="mag"></td>
</tr>
<tr>
<td width="170">
<div align="right">
Dhakar (GMT +6)</div>
</td>
<td><input type="text" size="8" name="dh"></td>
<td width="50"></td>
<td width="170">
<div align="right">
Wellington (GMT +12)</div>
</td>
<td><input type="text" size="8" name="wll"></td>
</tr>
</table>
</form>
</centre>
</body>


IF some one could tell me why .. would be great

And on another note, is there a way to have the GMT time be taken from a server and keep the local time box taking it from the system time ?

Thanks in advance for your help
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Aug 19 2007, 06:32 AM
Post #2


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



Haven't got time to reverse engineer your script, but it looks about 10 times bigger than it should be. You _never_ need to write 24 cases in sequence.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
AJ Knight
post Aug 19 2007, 06:54 AM
Post #3





Group: Members
Posts: 3
Joined: 19-August 07
Member No.: 3,584



Well Thank you for your help ... any useful sugguestions to someone who you more then likely picked up as a newbie ??

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
AJ Knight
post Aug 19 2007, 12:03 PM
Post #4





Group: Members
Posts: 3
Joined: 19-August 07
Member No.: 3,584



Through trail and error ... I have narrowed down the issue .. It only seems to happen between 12 noon and midnight on all the times including and below the GMT part of the clock ... I am still not sure why this is happening as the clocks above it seem not to suffer this issue ... and I cut and paste them down .. though the time is wrong .. it doesnt happen ...

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Aug 19 2007, 12:27 PM
Post #5


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



QUOTE(AJ Knight @ Aug 19 2007, 08:54 PM) *

Well Thank you for your help ... any useful sugguestions to someone who you more then likely picked up as a newbie ??


Write a function [eg!] showtime(zone, place) which takes a numeric value zone, being the number of hours before or after GMT, and a string place being the name of the archetypal city, and generates the time at that zone. Then you can have 24 calls, including things like showtime(9, 'Tokyo');

Now you have to write _one_ function, including the arithmetic, which you test until you get it right.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Aug 19 2007, 12:59 PM
Post #6


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



OK, lots of questions.

(1) Where on earth did you get this from?

And a comment: This programming is unbelievable junk. It makes CSS look well designed.

(1a) It's a bad idea to have Large Numbers of names embedded in the script as variable names. E.g. rome:

var rome =check24(((gmt + 1) > 24) ? ((gmt + 1)): (gmt + 1));

(1a-2) Why is your line for assigning to the variable rome different from the original?

(1b) What on earth is this for? (Choosing a different example, just because it looks hideous)

var east =check24(((gmt + (24-5)) > 24) ? ((gmt + (24-5)) - 24) : (gmt + (24-5)));

Let's assume that the variable gmt is supposed to be the hours value for gmt.
Then it looks as though east is supposed to be 5 hours earlier. We note that this should be "clock arithmetic", or arithmetic modulo 24. The function check24 looks like this:

function check24(hour) {
return (hour >= 24) ? hour - 24 : hour;
}

In other words, check24 takes an integer, and subtracts 24 if it is more than 23.
The expression inside check24 here is:

((gmt + (24-5)) > 24)
? ((gmt + (24-5)) - 24)
: (gmt + (24-5))

Truly amazing. The writer presumably does not know that addition is associative!

So we take gmt (range 0-23) and add 24 (now range 24-47) then subtract 5 (range now 19-42. If this is more than 24, we subtract 24. Range is now 1 to 24 (which is wrong, since we want 0 - 23). Finally we apply the check24 () function, which actually corrects the one wrong case! Grief! (If he had done the correct check here, the check24 function would be unnecessary.)

But all of this crap can be replaced by a % sign. If gmt is the gmt hours, and zone is the offset, the hours for the timezone are (gmt+zone)%24. The % (modulo) operator adjusts the value to be in the correct range.

(2) Why aren't you using a server side script?

(3) To answer my own question, http://www.gamarod.com.ar/en/javascript/so...pt.asp?code=215

Sorry, but this script is not worth wasting time on. Since the example page seems to work:

http://www.gamarod.com.ar/en/javascript/ex...pt.asp?code=215

... either copy it, or put a link to it, or forget the whole thing, or learn how to program properly.


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 13th May 2024 - 10:42 PM