@@ -94,5 +94,38 @@ def self.region_name(region_code)
9494 def self . countries_for_region ( region_code )
9595 REGIONS . dig ( region_code . upcase , :countries ) || [ ]
9696 end
97+
98+ TIMEZONE_TO_REGION = {
99+ # United States
100+ "America/New_York" => "US" , "America/Chicago" => "US" , "America/Denver" => "US" ,
101+ "America/Los_Angeles" => "US" , "America/Phoenix" => "US" , "America/Anchorage" => "US" ,
102+ "Pacific/Honolulu" => "US" , "America/Detroit" => "US" , "America/Indiana/Indianapolis" => "US" ,
103+ # Canada
104+ "America/Toronto" => "CA" , "America/Vancouver" => "CA" , "America/Edmonton" => "CA" ,
105+ "America/Winnipeg" => "CA" , "America/Halifax" => "CA" , "America/St_Johns" => "CA" ,
106+ # United Kingdom
107+ "Europe/London" => "UK" ,
108+ # EU countries
109+ "Europe/Paris" => "EU" , "Europe/Berlin" => "EU" , "Europe/Rome" => "EU" ,
110+ "Europe/Madrid" => "EU" , "Europe/Amsterdam" => "EU" , "Europe/Brussels" => "EU" ,
111+ "Europe/Vienna" => "EU" , "Europe/Stockholm" => "EU" , "Europe/Copenhagen" => "EU" ,
112+ "Europe/Helsinki" => "EU" , "Europe/Warsaw" => "EU" , "Europe/Prague" => "EU" ,
113+ "Europe/Budapest" => "EU" , "Europe/Athens" => "EU" , "Europe/Bucharest" => "EU" ,
114+ "Europe/Sofia" => "EU" , "Europe/Dublin" => "EU" , "Europe/Lisbon" => "EU" ,
115+ "Europe/Zagreb" => "EU" , "Europe/Ljubljana" => "EU" , "Europe/Bratislava" => "EU" ,
116+ "Europe/Tallinn" => "EU" , "Europe/Riga" => "EU" , "Europe/Vilnius" => "EU" ,
117+ "Europe/Luxembourg" => "EU" , "Europe/Malta" => "EU" ,
118+ # India
119+ "Asia/Kolkata" => "IN" , "Asia/Calcutta" => "IN" ,
120+ # Australia/NZ
121+ "Australia/Sydney" => "AU" , "Australia/Melbourne" => "AU" , "Australia/Brisbane" => "AU" ,
122+ "Australia/Perth" => "AU" , "Australia/Adelaide" => "AU" , "Australia/Hobart" => "AU" ,
123+ "Pacific/Auckland" => "AU" , "Pacific/Fiji" => "AU"
124+ } . freeze
125+
126+ def self . timezone_to_region ( timezone )
127+ return "XX" if timezone . blank?
128+ TIMEZONE_TO_REGION [ timezone ] || "XX"
129+ end
97130 end
98131end
0 commit comments