Rails "clock" and Javascript "clock" seconds apart.

Hi All,

I'm having a bit of an issue with time in my application. I'd be inclined to think that it was simply a machine time issue, but, as I've run the application on multiple machines, I'm not so sure.

Basically, my rails "current time" and my javascript "current time" are anywhere from 3 to 6 seconds apart. Is there any way for me to resolve this?

I suppose I could get a capture of each and add or subtract one from the other, but the trouble is that I'm using a timer, and the logic to ensure that the value doesn't re-change after the initial setting could get out of hand. Are there perhaps any "static var" additions to Javascript?

Thanks in advance for any suggestions.

Do you really expect your browser and the remote server clocks to be exactly in sync?

Yes, if they're running on the same system. In a distributed system, not at all, but it would be nice if it were *consistently* out of sync. Ya know? Still I need a mechanism to right the wrong. Thoughts?

Yes, if they're running on the same system. In a distributed system, not at all, but it would be nice if it were *consistently* out of sync. Ya know? Still I need a mechanism to right the wrong. Thoughts?

What exactly are you doing? Is the time difference just the difference
between when you evaluated Time.now in your app and when the page
finished loading and the browser started to run the javascript?

No, the difference is actually between the Javascript "Time.now", and the rails property "Object.created_at". What I did was just base the time on the server completely and worked some code like the following:

//SET SOME OTHER VALUES IN RAILS EARLIER

<script type="text/javascript">

function clockwatch()

  if (typeof initial_time == 'undef'){

    initial_time = <%= Time.new%>

  }

  initial_time++

  //perform my subtractions, etc here

}

</script>

My initial problem was the seeming lack of Javascript "static" types. But using that allowed me to sort of create a static object. Anyway, basing the time strictly on the server worked.

One question: If you use RJS does it get re-evaluated on each iteration, or does it get "pumped out" once-for-all-time like regular Javascript?

One question: If you use RJS does it get re-evaluated on each iteration, or does it get "pumped out" once-for-all-time like regular Javascript?

evaluated on each request.

Fred