isDateTimeValid method

Future<bool> isDateTimeValid({
  1. int toleranceInSeconds = 5,
})

Validates the device's system time by comparing it with the network time (NTP).

Returns true if the difference between the device time and the network time is within the specified toleranceInSeconds. Defaults to 5 seconds.

Implementation

Future<bool> isDateTimeValid({int toleranceInSeconds = 5}) async {
  networkTime = await _getNetworkTime();
  DateTime deviceTime = DateTime.now();
  debugPrint('Device time: $deviceTime');
  if (networkTime == null) {
    return false;
  }
  // Calculate absolute difference in seconds
  final difference = deviceTime.difference(networkTime!).inSeconds.abs();

  // Check if within tolerance
  return difference <= toleranceInSeconds;
}