handle files with missing timestamps

This commit is contained in:
vcoppe
2025-02-02 11:27:06 +01:00
parent 0b457f9a1e
commit 52984d4b70

View File

@@ -2006,6 +2006,8 @@ function withTimestamps(
if (last === undefined) { if (last === undefined) {
last = points[0].clone(); last = points[0].clone();
last.time = startTime; last.time = startTime;
} else if (last.time === undefined) {
last.time = startTime;
} }
return points.map((point) => { return points.map((point) => {
let time = getTimestamp(last, point, speed); let time = getTimestamp(last, point, speed);
@@ -2070,6 +2072,9 @@ function withArtificialTimestamps(
} }
function getTimestamp(a: TrackPoint, b: TrackPoint, speed: number): Date { function getTimestamp(a: TrackPoint, b: TrackPoint, speed: number): Date {
if (a.time === undefined) {
return undefined;
}
let dist = distance(a.getCoordinates(), b.getCoordinates()) / 1000; let dist = distance(a.getCoordinates(), b.getCoordinates()) / 1000;
return new Date(a.time.getTime() + (1000 * 3600 * dist) / speed); return new Date(a.time.getTime() + (1000 * 3600 * dist) / speed);
} }