forked from upstream-mirrors/OpenTracks
SensorData: use Instant instead of long.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user