summaryrefslogtreecommitdiff
path: root/web/frontend/ride-filters-logic.ts
blob: f3593c16dc532c958c5ab0e323bb9a8678880cb9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export type RideFilterRangeFormat = "distance" | "duration" | "cotacol";
export type RideFilterRangeHandle = "min" | "max";

export const formatRideFilterValue = (format: RideFilterRangeFormat, value: number): string => {
  if (format === "distance") return `${value} km`;
  if (format === "cotacol") return `${value} points`;
  const hours = Math.floor(value / 60);
  const minutes = value % 60;
  return `${hours}h ${String(minutes).padStart(2, "0")}m`;
};

export const normalizeRideFilterRange = (min: number, max: number, changed: RideFilterRangeHandle): { min: number; max: number } => {
  if (min <= max) return { min, max };
  return changed === "min" ? { min: max, max } : { min, max: min };
};