SensorData: use Instant instead of long.

This commit is contained in:
Dennis Guse
2021-02-07 23:16:12 +01:00
parent 854c8727e5
commit cd4e0abd6f
2 changed files with 10 additions and 10 deletions
@@ -4,6 +4,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import java.time.Instant;
import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
public class SensorData {
@@ -11,18 +13,18 @@ public class SensorData {
private final String sensorAddress;
private final String sensorName;
private final long timestamp_ms;
private final Instant timestamp_ms;
SensorData(String sensorAddress) {
this(sensorAddress, null, System.currentTimeMillis());
this(sensorAddress, null);
}
SensorData(String sensorAddress, String sensorName) {
this(sensorAddress, sensorName, System.currentTimeMillis());
this(sensorAddress, sensorName, Instant.now());
}
@VisibleForTesting
SensorData(String sensorAddress, String sensorName, long timestamp_ms) {
SensorData(String sensorAddress, String sensorName, Instant timestamp_ms) {
this.sensorAddress = sensorAddress;
this.sensorName = sensorName;
this.timestamp_ms = timestamp_ms;
@@ -42,10 +44,7 @@ public class SensorData {
return sensorName != null ? sensorName : sensorAddress;
}
/**
* Is the data recent considering the current time.
*/
public boolean isRecent() {
return timestamp_ms + BluetoothRemoteSensorManager.MAX_SENSOR_DATE_SET_AGE_MS > System.currentTimeMillis();
return Instant.now().isBefore(timestamp_ms.plus(BluetoothRemoteSensorManager.MAX_SENSOR_DATE_SET_AGE_MS));
}
}