Thursday, 22 August 2013

Sign of Firebase's clock skew

Sign of Firebase's clock skew

Firebase's docs about presence say that the "client's clock skew" is a
value "that Firebase will add to the local reported time (epoch time in
milliseconds) to estimate the server time".
Then, in the examples, it says for example:
@Override
public void onDataChange(DataSnapshot snapshot) {
double offset = snapshot.getValue(Double.class);
double estimatedServerTimeMs = System.currentTimeMillis() + offset;
}
On one Android device that I use for testing, I have changed the clock so
that it fast by 4 minutes (roughly). Now when I get the clock skew via the
Java SDK, the value I get is the following:
232599.0
As this is in milliseconds, it corresponds to 3.87665 minutes.
But to get an estimation for the server's time, I would have to add it to
the local timestamp (System.currentTimeMillis()). Is that right?
If the client's clock is already fast by 4 minutes, and I add those 3.9
minutes, don't I get an estimation that is fast by about 8 minutes?
By the way, it would be perfect if I could use the server timestamp in
setPriority(). Currently, ServerValue.Timestamp is only available for
setValue() as it is not a primitive value. As I want to use the time in
setPriority(), I have to calculate the server's time by using
System.currentTimeMillis() and the clock skew.

No comments:

Post a Comment