3b87b8c4e5
Replace mock data in geocoding, HAFAS, and bike routing clients with actual implementations using fetch and appropriate interfaces. Update typescript definitions to match the new data structures, including Journey, Station, and BikeRoute. Add vitest and related testing dependencies, replacing the placeholder test script with actual tests for the new client logic. Refactor calendar and countdown utilities to use the new types and remove unused files. Implement real API clients and update types Replace mock data in HafasClient, GeocodingClient, and BikeRoutingClient with actual fetch implementations. Update types to match API responses and add Vitest tests.
49 lines
928 B
TypeScript
49 lines
928 B
TypeScript
// Countdown utilities for ÖBB Planner
|
|
import { CountdownInfo } from "@/types";
|
|
|
|
export function calculateCountdown(targetDate: Date): CountdownInfo {
|
|
const now = new Date();
|
|
const diffMs = targetDate.getTime() - now.getTime();
|
|
const diffMin = Math.floor(diffMs / 60000);
|
|
|
|
if (diffMin <= 0) {
|
|
return {
|
|
label: "Now",
|
|
color: "red",
|
|
urgent: true,
|
|
};
|
|
}
|
|
|
|
if (diffMin <= 10) {
|
|
return {
|
|
label: `${diffMin}min`,
|
|
color: "orange",
|
|
urgent: true,
|
|
};
|
|
}
|
|
|
|
if (diffMin <= 30) {
|
|
return {
|
|
label: `${diffMin}min`,
|
|
color: "yellow",
|
|
urgent: false,
|
|
};
|
|
}
|
|
|
|
if (diffMin < 60) {
|
|
return {
|
|
label: `${diffMin}min`,
|
|
color: "green",
|
|
urgent: false,
|
|
};
|
|
}
|
|
|
|
const hours = Math.floor(diffMin / 60);
|
|
const remainingMin = diffMin % 60;
|
|
return {
|
|
label: `${hours}h ${remainingMin}min`,
|
|
color: "blue",
|
|
urgent: false,
|
|
};
|
|
}
|