JS Clock Shows Negative Time
This code shows time like this: 20:0-14:30 When Kabul is in the bottom half of the hour. Post the code and you'll see it, or I have a .jpg that will display it.
Please help me to fix this....
<script type="text/javascript" language="JavaScript">
<!--
// Global Variable Constants
var start_hr = <% = (HOUR(TIME())-4) + 24 mod 24 %>;
var start_min = <% = (MINUTE(TIME())-25) + 60 mod 60 %>;
var start_sec = <% = SECOND(TIME()) %>;
var char_offset = 3;
var est_offset = 1;
var zulu_offset = 0; // Zulu Time Offset
var dst = 'YES'; // Need a way to check for eastern time. This value is set manually for now.
var delta_offset = 4; // Delta Time Offset
var echo_offset = 30;
temp = (dst == 'NO') ? est_offset = -5: est_offset = -5;// Calculate the offset from Charlie to Eastern
function NewWindow(url_dest, win_height, win_width) {
var left_coord = screen.width/2-225;
var top_coord = screen.height/2-100;
if(!window.openwin || window.openwin.closed) {
openwin = this.open(url_dest, "CtrlWindow", "height=" + win_height + ",width=" + win_width + ",toolbar=no,menubar=no,location=mo,scrollbars=no,resizable=no,left=" + left_coord + ",top=" + top_coord);
} else {
openwin.focus();
}
}
function closeWindow() {
if(window.openwin) openwin.close();
}
// -->
</script>
<script src="script/jsclock.js" type="text/javascript" language="JavaScript"></script>
<div align="center">
<table>
<tr>
<form name="op_clock">
<td colspan="5" align="center">
<table cellpadding="0" cellspacing="0" border="1" bordercolor="Black">
<tr>
<td><input type="text" size="8" maxlength="10" value=" " name="est_time" class="clock"></td>
<td><input type="text" size="8" maxlength="10" value=" " name="zulu_time" class="clock"></td>
<td><input type="text" size="8" maxlength="10" value=" " name="charlie_time" class="clock"></td>
<td><input type="text" size="8" maxlength="10" value=" " name="delta_time" class="clock"></td>
<td><input type="text" size="8" maxlength="10" value=" " name="echo_time" class="clock"></td>
</tr>
<tr>
<td>Eastern</td>
<td>Zulu</td>
<td>Charlie</td>
<td>Delta</td>
<td><b>Delta +30</b></td>
</tr>
<tr>
<td>New York</td>
<td>London</td>
<td>Baghdad</td>
<td>Abu Dhabi, UAE</td>
<td><b>KABUL</b></td>
</tr>
</table>
<script type="text/javascript" language="JavaScript">
setInterval("increment_time()", 1000);
//
</script>
</td>
</form>
</tr>
</table>
Thank you
ROGER
Hi!
Without having the code of your file called in:
<script src="script/jsclock.js" type="text/javascript" language="JavaScript"></script>
it won't be amusing to find a solution for that problem.
Cheers - Pit
The Devils in the details!
I have included the JS code from the file below...
Thank you for pointing that out Pittimann!
Thank you Roger
// JavaScript Document
function set_time()
{
var esthr_string; // Eastern Time Hour String
var zhr_string; // Zulu Time Hour String
var hr_string; // Current System Time Hour String
var dhr_string; // Delta Time Hour String
var ehr_string; // Echo Time Hour String
var chr_string; // Charlie Time Hour String
var min_string; // EST, Zulu, Charlie, Delta Minute String
var sec_string; // EST, Zulu, Charlie, Delta, Echo Minute String
var emin_string; // Echo Time Minute String
var est_hour;
var zulu_hour;
var delta_hour;
var charlie_hour;
var echo_hour;
var echo_min;
var temp;
// Charlie hour modification
charlie_hour = start_hr + char_offset;
if(charlie_hour == 24)
{
chr_string = '00';
}
else if(charlie_hour < 10)
{
chr_string = '0' + charlie_hour;
}
else if(charlie_hour > 24)
{
charlie_hour = charlie_hour - 24;
chr_string = '0' + charlie_hour;
}
else
{
chr_string = charlie_hour;
}
// Eastern hour modification
est_hour = start_hr + est_offset;
if(est_hour < 0)
{
est_hour = 24 + est_hour;
}
if(est_hour < 10)
{
esthr_string = '0' + est_hour;
}
else
{
esthr_string = est_hour;
}
// Zulu hour modification
zulu_hour = start_hr + zulu_offset;
if(zulu_hour < 0)
{
zulu_hour = 24 + zulu_hour;
}
if(zulu_hour < 10)
{
zhr_string = '0' + zulu_hour;
}
else
{
zhr_string = zulu_hour;
}
// Delta hour modification
delta_hour = start_hr + delta_offset;
if(delta_hour == 24)
{
dhr_string = '00';
}
else if(delta_hour < 10)
{
dhr_string = '0' + delta_hour;
}
else if (delta_hour > 24)
{
delta_hour = delta_hour - 24;
dhr_string = '0' + delta_hour;
}
else
{
dhr_string = delta_hour;
}
// Echo hour modification
echo_hour = delta_hour;
echo_min = start_min + echo_offset;
if(echo_hour == 24)
{
ehr_string = '0' + echo_hour;
}
else if (echo_hour > 24)
{
echo_hour = echo_hour - 24;
ehr_string = '0' + echo_hour;
}
else
{
ehr_string = echo_hour;
}
if(echo_min >= 60)
{
echo_min = echo_min - 60;
if(start_hr == 23)
{
echo_hour = 0;
}
else
{
echo_hour = echo_hour + 1;
}
}
else
{
echo_min = start_min + echo_offset;
}
temp = (echo_hour > 24) ? ehr_string = echo_hour - 24 : ehr_string = echo_hour;
temp = (echo_hour < 10) ? ehr_string = '0' + echo_hour : ehr_string = echo_hour;
temp = (echo_min < 10) ? emin_string = '0' + echo_min : emin_string = echo_min;
// Start hour default string
temp = (start_hr < 10) ? hr_string = '0' + start_hr : hr_string = start_hr;
temp = (start_min < 10) ? min_string = '0' + start_min : min_string = start_min;
temp = (start_sec < 10) ? sec_string = '0' + start_sec : sec_string = start_sec;
// Populate form fields
document.op_clock.est_time.value = esthr_string + ':' + min_string + ':' + sec_string;
document.op_clock.zulu_time.value = zhr_string + ':' + min_string + ':' + sec_string;
document.op_clock.charlie_time.value = chr_string + ':' + min_string + ':' + sec_string;
document.op_clock.delta_time.value = dhr_string + ':' + min_string + ':' + sec_string;
document.op_clock.echo_time.value = ehr_string + ':' + emin_string + ':' + sec_string;
increment_time();
}
function increment_time()
{
var esthr_string; // Eastern Time Hour String
var zhr_string; // Zulu Time Hour String
var hr_string; // Charlie Time Hour String
var dhr_string; // Delta Time Hour String
var chr_string; // Charlie Time Hour String
var min_string;
var sec_string;
var est_hour;
var zulu_hour;
var delta_hour;
var char_hour;
var temp;
if(start_sec == 59)
{
start_sec = 0;
if(start_min == 59)
{
start_min = 0;
if(start_hr == 23)
{
start_hr = 0;
}
else
{
start_hr = start_hr + 1;
}
}
else
{
start_min = start_min + 1;
}
} // end if
else
{
start_sec = start_sec + 1;
} // end else
// Charlie hour modification
charlie_hour = start_hr + char_offset;
if(charlie_hour == 24)
{
chr_string = '00';
}
else if(charlie_hour < 10)
{
chr_string = '0' + charlie_hour;
}
else if(charlie_hour > 24)
{
charlie_hour = charlie_hour - 24;
chr_string = '0' + charlie_hour;
}
else
{
chr_string = charlie_hour;
}
// Eastern hour modification
est_hour = start_hr + est_offset;
if(est_hour < 0)
{
est_hour = 24 + est_hour;
}
if(est_hour < 10)
{
esthr_string = '0' + est_hour;
}
else
{
esthr_string = est_hour;
}
// Zulu hour modification
zulu_hour = start_hr +zulu_offset;
if(zulu_hour < 0)
{
zulu_hour = 24 + zulu_hour;
}
if(zulu_hour < 10)
{
zhr_string = '0' + zulu_hour;
}
else
{
zhr_string = zulu_hour;
}
// Delta time modification
delta_hour = start_hr + delta_offset;
if(delta_hour == 24)
{
dhr_string = '00';
}
else if(delta_hour < 10)
{
dhr_string = '0' + delta_hour;
}
else if (delta_hour > 24)
{
delta_hour = delta_hour - 24;
dhr_string = '0' + delta_hour;
}
else
{
dhr_string = delta_hour;
}
// Echo hour modification
echo_hour = delta_hour;
echo_min = start_min + echo_offset;
if(echo_hour == 24)
{
ehr_string = '0' + echo_hour;
}
else if (echo_hour > 24)
{
echo_hour = echo_hour - 24;
ehr_string = '0' + echo_hour;
}
else
{
ehr_string = echo_hour;
}
if(echo_min >= 60)
{
echo_min = echo_min - 60;
if(start_hr == 23)
{
echo_hour = 0;
}
else
{
echo_hour = echo_hour + 1;
}
}
else
{
echo_min = start_min + echo_offset;
}
temp = (echo_hour > 24) ? ehr_string = echo_hour - 24 : ehr_string = echo_hour;
temp = (echo_hour < 10) ? ehr_string = '0' + echo_hour : ehr_string = echo_hour;
temp = (echo_min < 10) ? emin_string = '0' + echo_min : emin_string = echo_min;
// Start hour default string
temp = (start_hr < 10) ? hr_string = '0' + start_hr : hr_string = start_hr;
temp = (start_min < 10) ? min_string = '0' + start_min : min_string = start_min;
temp = (start_sec < 10) ? sec_string = '0' + start_sec : sec_string = start_sec;
// Populate form fields
document.op_clock.est_time.value = esthr_string + ':' + min_string + ':' + sec_string;
document.op_clock.zulu_time.value = zhr_string + ':' + min_string + ':' + sec_string;
document.op_clock.charlie_time.value = chr_string + ':' + min_string + ':' + sec_string;
document.op_clock.delta_time.value = dhr_string + ':' + min_string + ':' + sec_string;
document.op_clock.echo_time.value = ehr_string + ':' + emin_string + ':' + sec_string;
}
Hi!
Please try this, where the global vars are defined (pure javascript, not - like in your case, something else):
// Global Variable Constants
today = new Date();
var start_hr = today.getUTCHours();
var start_min = today.getUTCMinutes()
var start_sec = today.getUTCSeconds()
This should work around the clock...
Cheers - Pit
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks