mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 01:54:43 +00:00
Add brewery discovery & detail pages with location-based search (#253)
This commit is contained in:
9
web/frontend/app/features/breweries/utils/distance.ts
Normal file
9
web/frontend/app/features/breweries/utils/distance.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export type DistanceUnit = 'km' | 'mi';
|
||||
|
||||
const METRES_PER_MILE = 1609.344;
|
||||
|
||||
export const formatDistance = (metres: number, unit: DistanceUnit = 'km'): string => {
|
||||
const value = unit === 'mi' ? metres / METRES_PER_MILE : metres / 1000;
|
||||
const rounded = value < 10 ? value.toFixed(1) : String(Math.round(value));
|
||||
return `${rounded} ${unit}`;
|
||||
};
|
||||
Reference in New Issue
Block a user