storeServerTimeOffset method

Future<void> storeServerTimeOffset(
  1. SchemaMetaData smd,
  2. DbTransaction transaction,
  3. int currentTs,
  4. int serverTs,
)

Implementation

Future<void> storeServerTimeOffset(SchemaMetaData smd,
    DbTransaction transaction, int currentTs, int serverTs) async {
  bool inRange = false;
  int timeDifference = serverTs - currentTs;
  int serverTimeOffset = await getConfigurationInteger(
      smd, transaction, ConfigurationNameEnum.SERVER_TIME_OFFSET) as int;
  if ((timeDifference > (serverTimeOffset - _C_SLACK_SECS)) &&
      (timeDifference < (serverTimeOffset + _C_SLACK_SECS))) inRange = true;
  if (!inRange) {
    await setConfigurationInteger(smd, transaction,
        ConfigurationNameEnum.SERVER_TIME_OFFSET, timeDifference);
  }
  print(
      "currentTs=$currentTs||serverTs=$serverTs||diff=$timeDifference||stored offset=$serverTimeOffset");
}