View Full Version : Strange bug with timezones

03-16-2005, 05:26 PM
So here i have some strange problem. I designed a system to display specified number of lines from array. The number of lines to display is counted this way:
1. timestamp is taken when should it start displaying;
2. number of seconds is set after each additional line should be displayed.
3. total lines are counted.

here is the code:

<script type="text/javascript" src="formatDate.js"></script>
<script type="text/javascript">
var timer = null
var text = new Array('.$lines.')
var l = 0
var quart1 = 0
var quart2 = 0
var quart3 = 0
var timeperline = '.$timeperline.'

function writetext()
textToDisplay = ""
for(i=0; i<l; i++)
textToDisplay += text[i] + "<br />"
document.getElementById("div1").innerHTML = textToDisplay;

function stop()

function start()
var time = new Date()
var hours = time.getHours()
var minutes = time.getMinutes()
var seconds = time.getSeconds()
var unix = time.formatDate("U")
var x = '. ($hour + 1) .'
unix = Math.round(unix/1000)
document.getElementById("div2").innerHTML = unix
if (unix > '. ($time + 3000) .' && unix <= '.$time4.')
dabartis = hours*3600 + minutes*60 + seconds - x*3600
l = dabartis/timeperline
l = Math.round(l)
l = (l > 0) ? l : 0
l = (l < '.$lines.') ? l : '.$lines.'
var clock = time.formatDate("i:s")
document.getElementById("clock").innerHTML = clock
if (unix == '.$time4.')
document.location.href = \'match.php?matchid='.$matchid.'\'
timer = setTimeout("start()",1000)
else if (unix > '. ($time + 3600) .' + timeperline * '. $lines .')
l = '.$lines.'
<body onload="start()" onunload="stop()">

this is php script with javascript inside...
formatDate.js is a set of functions.. similar to ones used by php
now the script has some strange behavior..
the time is set correctly, everything works fine as it should for those who are in same timezone as server. It is servertime in var unix.
text is added to array at other place in order to make it less vissible for users who looks at source. The script is set to display number of lines counted in function.
Now the time comes to start displaying lines..
For people in other timezones it doesnt display the lines... However it refreshes the page when all lines should be displayed and displays it then. But until then none of the lines displayed. (It works perfectly for people in same timezone as server and works perfectly if sets their pc clock to server timezone) Could someone explain why this happens? because i am searching for a reason more than a week now and i am going crazy about it. What influence timezone have here, because all times are servertime and none of them are usertime...

03-17-2005, 02:50 AM
What influence timezone have here, because all times are servertime and none of them are usertime...
But this is user time:

var time = new Date()

You should have passed the server time in the Date constructor.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum