Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Strange bug with timezones

    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:
    Code:
                            <script type="text/javascript" src="formatDate.js"></script>
    			<script type="text/javascript">
    				var timer = null
    				var text = new Array('.$lines.')
    				');
    				print('
    				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()
    				{
    				clearTimeout(timer)
    				}
    				
    				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
    						writetext()
    						if (unix == '.$time4.')
    						{
    							document.location.href = \'match.php?matchid='.$matchid.'\'
    						}
    						timer = setTimeout("start()",1000)
    					}
    					else if (unix > '. ($time + 3600) .' + timeperline * '. $lines .')
    					{
    						l = '.$lines.'
    						writetext()
    					}
    				}
    			</script>
    			</head>
    			<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...

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by Rokas
    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.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •