forked from upstream-mirrors/OpenTracks
Workaround for GPS week rollover (happening every 19.7 years).
Fixes #155. https://en.wikipedia.org/wiki/GPS_Week_Number_Rollover
This commit is contained in:
@@ -17,13 +17,23 @@ public class TrackPointUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Ancient fix for phones that do not set the time in {@link android.location.Location}.
|
||||
* 1. Ancient fix for phones that do not set the time in {@link android.location.Location}.
|
||||
* 2. Fix for GPS time rollover happening every 19.7 years: https://en.wikipedia.org/wiki/GPS_Week_Number_Rollover
|
||||
*/
|
||||
//TODO Necessary?
|
||||
public static void fixTime(@NonNull TrackPoint trackPoint) {
|
||||
if (trackPoint.getTime() == 0L) {
|
||||
Log.w(TAG, "Time of provided location was 0. Using current time.");
|
||||
trackPoint.setTime(System.currentTimeMillis());
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
long timeDiff = Math.abs(trackPoint.getTime() - System.currentTimeMillis());
|
||||
|
||||
if (timeDiff > 1023 * UnitConversions.ONE_WEEK_MS) {
|
||||
Log.w(TAG, "GPS week rollover.");
|
||||
trackPoint.setTime(trackPoint.getTime() + 1024 * UnitConversions.ONE_WEEK_MS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user