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.

On Fri, 20 Jun 2008, gberz3 wrote:

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?

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


A

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?

On Jun 22, 5:34 am, Frederick C. [email protected]
wrote:

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

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

On 21 Jun 2008, at 02:16, gberz3 wrote:

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?