1

I'm developing a website that uses Comet to transmit data back to web clients. My application is very time sensitive, I have a graph displaying points added every second.

Since the web application is Comet driven there is no real need for the client to handle dates, it should only use the server timestamp to display information. i.e. a plotted point on the graph should display in the tooltip the server timestamp, regardless of the user's timezone.

I think my best approach would be to retrieve the server's timestamp using REST. Then measure the timezone offset between the server and client time, add/deduct the difference and use it as the client's timestamp for display purposes.

Is there a way to override the default behavior of new Date() to result in me having the server's timestamp as the local?

Many thanks.

itayw
  • 614
  • 9
  • 20

2 Answers2

1

I wrote the library TimeShift.js that allows overriding the Date constructor and setting the current time and time zone. I wrote it for testing purposes, but it could be used for other uses as well.

Be sure to check the caveats of the current library. It currently only supports a fixed offset to GMT, so DST changes are not supported.

Sampo
  • 4,308
  • 6
  • 35
  • 51
0

just redefine it, it should work fine:

if(Date) {
    try{
        Date = null;
        Date = function() {
            console.log("The more things change, the more they stay the same!");
        }
        Date();
    } catch(exeption) {
        console.log("Couldn't override Date object.");
    }
}
Sepehr
  • 2,051
  • 19
  • 29