Account for origin walk in departure time

Add useOriginStationWalk and integrate it into EventDetail/EventList to
resolve walking time from origin to station. Introduce calculateLeaveByTime
for notification scheduling and use exported Expo trigger types. Support
HAFAS 'crd' coordinates in client and destination hooks, update tests,
jest mappings, and Expo run scripts.
This commit is contained in:
2026-05-18 11:56:49 +02:00
parent 9d6efdd43b
commit ce1fa4972c
14 changed files with 381 additions and 62 deletions
+11 -7
View File
@@ -249,7 +249,11 @@ export class ApiClient {
async findNearestStationByCoords(lat: number, lng: number): Promise<Station | null> {
interface HafasLocation extends Station {
type: string;
lon: number;
lon?: number;
crd?: {
x?: number;
y?: number;
};
}
const result = await this.hafasRequest<{
@@ -284,10 +288,10 @@ export class ApiClient {
// Find the closest station by Euclidean distance
const closest = stationResults.reduce((best: HafasLocation, candidate: HafasLocation) => {
const bestLat = normalizeHafasCoordinate(best.lat) ?? lat;
const bestLng = normalizeHafasCoordinate(best.lng ?? best.lon) ?? lng;
const candidateLat = normalizeHafasCoordinate(candidate.lat) ?? lat;
const candidateLng = normalizeHafasCoordinate(candidate.lng ?? candidate.lon) ?? lng;
const bestLat = normalizeHafasCoordinate(best.lat ?? best.crd?.y) ?? lat;
const bestLng = normalizeHafasCoordinate(best.lng ?? best.lon ?? best.crd?.x) ?? lng;
const candidateLat = normalizeHafasCoordinate(candidate.lat ?? candidate.crd?.y) ?? lat;
const candidateLng = normalizeHafasCoordinate(candidate.lng ?? candidate.lon ?? candidate.crd?.x) ?? lng;
const bestDist = Math.hypot(bestLat - lat, bestLng - lng);
const candDist = Math.hypot(candidateLat - lat, candidateLng - lng);
return candDist < bestDist ? candidate : best;
@@ -296,8 +300,8 @@ export class ApiClient {
return {
name: closest.name,
extId: closest.extId,
lat: normalizeHafasCoordinate(closest.lat),
lng: normalizeHafasCoordinate(closest.lng ?? closest.lon),
lat: normalizeHafasCoordinate(closest.lat ?? closest.crd?.y),
lng: normalizeHafasCoordinate(closest.lng ?? closest.lon ?? closest.crd?.x),
};
}