diff --git a/gpx/src/gpx.ts b/gpx/src/gpx.ts index cc32e928..52476a99 100644 --- a/gpx/src/gpx.ts +++ b/gpx/src/gpx.ts @@ -529,10 +529,14 @@ export class TrackSegment extends GPXTreeLeaf { statistics.local.elevation.loss.push(statistics.global.elevation.loss); // time - if (points[0].time !== undefined && points[i].time !== undefined) { - statistics.local.time.total.push((points[i].time.getTime() - points[0].time.getTime()) / 1000); - } else { + if (points[i].time === undefined) { statistics.local.time.total.push(undefined); + } else { + if (statistics.global.time.start === undefined) { + statistics.global.time.start = points[i].time; + } + statistics.global.time.end = points[i].time; + statistics.local.time.total.push((points[i].time.getTime() - statistics.global.time.start.getTime()) / 1000); } // speed @@ -557,7 +561,7 @@ export class TrackSegment extends GPXTreeLeaf { statistics.global.bounds.northEast.lon = Math.max(statistics.global.bounds.northEast.lon, points[i].attributes.lon); } - statistics.global.time.total = statistics.local.time.total[statistics.local.time.total.length - 1] ?? 0; + statistics.global.time.total = statistics.global.time.start && statistics.global.time.end ? (statistics.global.time.end.getTime() - statistics.global.time.start.getTime()) / 1000 : 0; statistics.global.speed.total = statistics.global.time.total > 0 ? statistics.global.distance.total / (statistics.global.time.total / 3600) : 0; statistics.global.speed.moving = statistics.global.time.moving > 0 ? statistics.global.distance.moving / (statistics.global.time.moving / 3600) : 0; @@ -846,6 +850,8 @@ export class GPXStatistics { total: number, }, time: { + start: Date | undefined, + end: Date | undefined, moving: number, total: number, }, @@ -888,6 +894,8 @@ export class GPXStatistics { total: 0, }, time: { + start: undefined, + end: undefined, moving: 0, total: 0, }, @@ -947,6 +955,9 @@ export class GPXStatistics { this.global.distance.total += other.global.distance.total; this.global.distance.moving += other.global.distance.moving; + this.global.time.start = this.global.time.start !== undefined && other.global.time.start !== undefined ? new Date(Math.min(this.global.time.start.getTime(), other.global.time.start.getTime())) : this.global.time.start ?? other.global.time.start; + this.global.time.end = this.global.time.end !== undefined && other.global.time.end !== undefined ? new Date(Math.max(this.global.time.end.getTime(), other.global.time.end.getTime())) : this.global.time.end ?? other.global.time.end; + this.global.time.total += other.global.time.total; this.global.time.moving += other.global.time.moving; @@ -970,6 +981,9 @@ export class GPXStatistics { statistics.global.distance.total = this.local.distance.total[end - 1] - this.local.distance.total[start]; statistics.global.distance.moving = this.local.distance.moving[end - 1] - this.local.distance.moving[start]; + statistics.global.time.start = this.local.points[start].time; + statistics.global.time.end = this.local.points[end - 1].time; + statistics.global.time.total = this.local.time.total[end - 1] - this.local.time.total[start]; statistics.global.time.moving = this.local.time.moving[end - 1] - this.local.time.moving[start]; diff --git a/website/package-lock.json b/website/package-lock.json index a51b4f68..ca00240a 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -8,6 +8,7 @@ "name": "website", "version": "0.0.1", "dependencies": { + "@internationalized/date": "^3.5.4", "@mapbox/mapbox-gl-geocoder": "^5.0.2", "bits-ui": "^0.21.10", "chart.js": "^4.4.2", @@ -777,9 +778,9 @@ "dev": true }, "node_modules/@internationalized/date": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/@internationalized/date/-/date-3.5.2.tgz", - "integrity": "sha512-vo1yOMUt2hzp63IutEaTUxROdvQg1qlMRsbCvbay2AK2Gai7wIgCyK5weEX3nHkiLgo4qCXHijFNC/ILhlRpOQ==", + "version": "3.5.4", + "resolved": "https://registry.npmjs.org/@internationalized/date/-/date-3.5.4.tgz", + "integrity": "sha512-qoVJVro+O0rBaw+8HPjUB1iH8Ihf8oziEnqMnvhJUSuVIrHOuZ6eNLHNvzXJKUvAtaDiqMnRlg8Z2mgh09BlUw==", "dependencies": { "@swc/helpers": "^0.5.0" } diff --git a/website/package.json b/website/package.json index 0cb101eb..b8d69d2a 100644 --- a/website/package.json +++ b/website/package.json @@ -41,6 +41,7 @@ }, "type": "module", "dependencies": { + "@internationalized/date": "^3.5.4", "@mapbox/mapbox-gl-geocoder": "^5.0.2", "bits-ui": "^0.21.10", "chart.js": "^4.4.2", diff --git a/website/src/lib/components/toolbar/Toolbar.svelte b/website/src/lib/components/toolbar/Toolbar.svelte index 062a13fb..05faf467 100644 --- a/website/src/lib/components/toolbar/Toolbar.svelte +++ b/website/src/lib/components/toolbar/Toolbar.svelte @@ -35,7 +35,7 @@ - {$_('toolbar.time_tooltip')} + {$_('toolbar.time.tooltip')} diff --git a/website/src/lib/components/toolbar/ToolbarItemMenu.svelte b/website/src/lib/components/toolbar/ToolbarItemMenu.svelte index 2543e9fe..c19abe0a 100644 --- a/website/src/lib/components/toolbar/ToolbarItemMenu.svelte +++ b/website/src/lib/components/toolbar/ToolbarItemMenu.svelte @@ -5,6 +5,7 @@ import Routing from '$lib/components/toolbar/tools/routing/Routing.svelte'; import Scissors from '$lib/components/toolbar/tools/Scissors.svelte'; import Waypoint from '$lib/components/toolbar/tools/Waypoint.svelte'; + import Time from '$lib/components/toolbar/tools/Time.svelte'; import Merge from '$lib/components/toolbar/tools/Merge.svelte'; import Clean from '$lib/components/toolbar/tools/Clean.svelte'; import Reduce from '$lib/components/toolbar/tools/Reduce.svelte'; @@ -39,6 +40,8 @@ {:else if $currentTool === Tool.WAYPOINT} + {:else if $currentTool === Tool.TIME} +