Frerit / epiclock

Automatically exported from code.google.com/p/epiclock
0 stars 0 forks source link

JS library uses client local time #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is a pretty fundamental flaw, which may or may not be recoverable,
but: this library uses the client's clock to calculate offset from a
start/end time.

However - it's not good practice to trust the client's clock!

Example: my server can send a start time for a count-up clock of 22:00 GMT.
If the client's clock is set differently to mine - say it's a half hour
behind, for whatever reason - you're going to get wrong results shown to
the user.

Realistically we should be sending a number of seconds since/to the event -
as calculated by the server - and either incrementing or decrementing this
value on the client side for display.

Original issue reported on code.google.com by lith...@gmail.com on 18 Mar 2010 at 11:43

GoogleCodeExporter commented 9 years ago
I've added a new clock mode to handle your request of displaying the server 
time. I haven't added 
documentation on it yet, but you can use this new clock as follows:

// Once the dom loads...     
     jQuery(function(){             
        jQuery('#clock') 
            .epiclock({mode: EC_EXPLICIT, target: 'March 18, 2010 11:59:54 PM EDT'})      // We define the clock...   
            .clocks(EC_RUN); // Then start the manager. 
     });

The target parameter should be a valid input representing the time from the 
server. This will render a clock 
which treats the target value as the actual starting value, renders it as a 
clock, and keeps time by counting the 
second offset from when the clock starts.

Let me know if you have any further issues. Released and available in the 
downloads section as release 3.2.3

Original comment by gars...@gmail.com on 19 Mar 2010 at 2:55

GoogleCodeExporter commented 9 years ago
This should handle the default clock type counter. However, if you want to 
mimic the explicit clock 
functionality for one of the other clocks, you should be able to replicate it 
by calling:

jQuery('#clock').epiclock({mode: ..., displace: - new Date().valueOf()});

This isn't tested, though, and may not work as expected. I've had a bit of beer 
tonight, and am only 
speculating as to the functionality for non-EC_EXPLICIT modes.

Original comment by gars...@gmail.com on 19 Mar 2010 at 3:02