Files
calendar/packages/features/cityTimezones/cityTimezonesHandler.ts
T
luzpazandGitHub 197a7ba6e9 fix: typos in packages/features (#19220)
Found via `codespell -q 3 -S "*.svg,./apps/web/public/static/locales,./packages/app-store/stripepayment/lib/currencyOptions.ts,./packages/lib/freeEmailDomainCheck/freeEmailDomains.ts" -L afterall,atleast,datea,fo,incase,ist,nam,notin,optionel,perview,reccuring`

Closes #19219
2025-02-21 05:14:57 -03:00

32 lines
1.2 KiB
TypeScript

import { cityMapping as allCities } from "city-timezones";
export type CityTimezones = Awaited<ReturnType<typeof cityTimezonesHandler>>;
export const cityTimezonesHandler = async () => {
/**
* Filter out all cities that have the same "city" key and only use the one with the highest population.
* This way we return a new array of cities without running the risk of having more than one city
* with the same name on the dropdown and prevent users from mistaking the time zone of the desired city.
*/
const topPopulatedCities: { [key: string]: { city: string; timezone: string; pop: number } } = {};
allCities.forEach((city) => {
const cityPopulationCount = city.pop;
if (
topPopulatedCities[city.city]?.pop === undefined ||
cityPopulationCount > topPopulatedCities[city.city].pop
) {
topPopulatedCities[city.city] = { city: city.city, timezone: city.timezone, pop: city.pop };
}
});
const uniqueCities = Object.values(topPopulatedCities);
/** Add specific overrides in here */
uniqueCities.forEach((city) => {
if (city.city === "London") city.timezone = "Europe/London";
if (city.city === "Londonderry") city.city = "London";
});
return uniqueCities;
};
export default cityTimezonesHandler;