I have written a TimeValidityCheckUtil
which determines if the snapshot from a particular listener is within a given time-frame of the current time of the device. This has this method, checkIfTImeValid
public static boolean checkIfTimeValid(Timestamp dbTimestamp)
{
Timestamp currentTimestamp = Timestamp.now();
Long seconds = currentTimestamp.getSeconds() - dbTimestamp.getSeconds();
if(seconds> 10)
{
return false;
}
return true;
}
The database structure is in Firestore and is as follows:
"ABC"-|
|
|-"documentId"-|
|
|-"some_key" - "string"
|-"timestamp" - timestamp
This is what happens, device A creates a documentId and the object with the timestamp.
Device B listens to this documentId and invokes the checkIfTimeValid
to check if the the operation by document A was within 10s of the current Timestamp (to check if it's recent)
Even if this process is happening instantly, the device shows the difference between the timestamps as ~57-62s which according to me should not be more than 1-5s.
Why this is happening?