import * as timezoneData from 'moment-timezone/data/meta/latest.json' import { getCountriesList } from '../../utils/countries' interface TimezoneContent { name: string countries: string[] } interface TimezoneData { [key: string]: TimezoneContent } export function getCountryFromTimezone(): string | null { const countryCode = getCountryCodeFromTimezone() const countryList = getCountriesList() return countryList[countryCode] || null } export function getCountryCodeFromTimezone(): string { const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone return detectCountry(timezone) } export function getCountryCodeFromCountryName(countryName: string): string { const countryList = getCountriesList() const countryCode = Object.keys(countryList).find((key) => countryList[key] === countryName) return countryCode || '' } function detectCountry(timezone: string): string { const zoneData: TimezoneData = timezoneData.zones try { return zoneData[timezone].countries[0] } catch (err) { console.warn('default zone if not found') } return 'AE' }