diff --git a/src/lib/components/lnv/sidebar/InRouteSidebar.svelte b/src/lib/components/lnv/sidebar/InRouteSidebar.svelte index 1b65254..09a782f 100644 --- a/src/lib/components/lnv/sidebar/InRouteSidebar.svelte +++ b/src/lib/components/lnv/sidebar/InRouteSidebar.svelte @@ -121,9 +121,37 @@ if (dist < 1000) return `${dist} m`; return `${dist / 1000} km`; }); + + // + // Calculating time left + // + function formatTimeLeft(seconds: number) { + if (seconds < 60) return `${Math.round(seconds)} s`; + if (seconds < 3600) return `${Math.round(seconds / 60)} min`; + const h = Math.floor(seconds / 3600); + const m = Math.round((seconds % 3600) / 60); + if (m === 0) return `${h} h`; + return `${h} h ${m} min`; + } + + function getTimeLeft(): number { + // TODO: include partial maneuver time + if (!routing.currentTrip) return 0; + let total = 0; + for (const [index, maneuver] of routing.currentTrip.legs[0].maneuvers.entries()) { + if (index >= routing.currentTripInfo.maneuverIdx) { + total += maneuver.time; + } + } + return total; + } + + const timeLeft = $derived.by(() => { + return formatTimeLeft(getTimeLeft()); + }) -{fullDistanceText} +{fullDistanceText}, {timeLeft} {m["sidebar.in-route.left"]()}