From de33fa8aae90fdf52e7322046c59350dcec4a5b5 Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Thu, 25 May 2023 01:05:37 +0800 Subject: [PATCH] Update list of Windows time zones --- scripts/generate_windows_zone_names.cr | 27 +++--- src/crystal/system/win32/zone_names.cr | 114 +++++++++++++------------ 2 files changed, 70 insertions(+), 71 deletions(-) diff --git a/scripts/generate_windows_zone_names.cr b/scripts/generate_windows_zone_names.cr index 9d70ff371373..6ab301033cf3 100644 --- a/scripts/generate_windows_zone_names.cr +++ b/scripts/generate_windows_zone_names.cr @@ -1,32 +1,24 @@ +#! /usr/bin/env crystal +# # This script generates the file src/crystal/system/win32/zone_names.cr # that contains mappings for windows time zone names based on the values -# found in http://unicode.org/cldr/data/common/supplemental/windowsZones.xml +# found in https://github.com/unicode-org/cldr/blob/main/common/supplemental/windowsZones.xml require "http/client" require "xml" require "../src/compiler/crystal/formatter" -WINDOWS_ZONE_NAMES_SOURCE = "http://unicode.org/cldr/data/common/supplemental/windowsZones.xml" +WINDOWS_ZONE_NAMES_SOURCE = "https://raw.githubusercontent.com/unicode-org/cldr/main/common/supplemental/windowsZones.xml" TARGET_FILE = File.join(__DIR__, "..", "src", "crystal", "system", "win32", "zone_names.cr") response = HTTP::Client.get(WINDOWS_ZONE_NAMES_SOURCE) - -# Simple redirection resolver -# TODO: Needs to be replaced by proper redirect handling that should be provided by `HTTP::Client` -if (300..399).includes?(response.status_code) && (location = response.headers["Location"]?) - response = HTTP::Client.get(location) -end - xml = XML.parse(response.body) - nodes = xml.xpath_nodes("/supplementalData/windowsZones/mapTimezones/mapZone[@territory=001]") -entries = [] of {key: String, zones: {String, String}, tzdata_name: String} - -nodes.each do |node| +entries = nodes.compact_map do |node| location = Time::Location.load(node["type"]) next unless location - time = Time.now(location).at_beginning_of_year + time = Time.local(location).at_beginning_of_year zone1 = time.zone zone2 = (time + 6.months).zone @@ -38,20 +30,21 @@ nodes.each do |node| zones = {zone1.name, zone2.name} end - entries << {key: node["other"], zones: zones, tzdata_name: location.name} + {key: node["other"], zones: zones, tzdata_name: location.name} rescue err : Time::Location::InvalidLocationNameError pp err + nil end # sort by IANA database identifier entries.sort_by! &.[:tzdata_name] hash_items = String.build do |io| - entries.each do |entry| + entries.join(io, '\n') do |entry| entry[:key].inspect(io) io << " => " entry[:zones].inspect(io) - io << ", # " << entry[:tzdata_name] << '\n' + io << ", # " << entry[:tzdata_name] end end diff --git a/src/crystal/system/win32/zone_names.cr b/src/crystal/system/win32/zone_names.cr index b29df3597772..74898c4a8389 100644 --- a/src/crystal/system/win32/zone_names.cr +++ b/src/crystal/system/win32/zone_names.cr @@ -6,104 +6,109 @@ module Crystal::System::Time # These mappings for windows time zone names are based on - # http://unicode.org/cldr/data/common/supplemental/windowsZones.xml + # https://raw.githubusercontent.com/unicode-org/cldr/main/common/supplemental/windowsZones.xml WINDOWS_ZONE_NAMES = { - "Egypt Standard Time" => {"EET", "EET"}, # Africa/Cairo - "Morocco Standard Time" => {"WET", "WEST"}, # Africa/Casablanca + "Egypt Standard Time" => {"EET", "EEST"}, # Africa/Cairo + "Morocco Standard Time" => {"+01", "+01"}, # Africa/Casablanca "South Africa Standard Time" => {"SAST", "SAST"}, # Africa/Johannesburg + "South Sudan Standard Time" => {"CAT", "CAT"}, # Africa/Juba + "Sudan Standard Time" => {"CAT", "CAT"}, # Africa/Khartoum "W. Central Africa Standard Time" => {"WAT", "WAT"}, # Africa/Lagos "E. Africa Standard Time" => {"EAT", "EAT"}, # Africa/Nairobi + "Sao Tome Standard Time" => {"GMT", "GMT"}, # Africa/Sao_Tome "Libya Standard Time" => {"EET", "EET"}, # Africa/Tripoli - "Namibia Standard Time" => {"WAT", "WAST"}, # Africa/Windhoek + "Namibia Standard Time" => {"CAT", "CAT"}, # Africa/Windhoek "Aleutian Standard Time" => {"HST", "HDT"}, # America/Adak "Alaskan Standard Time" => {"AKST", "AKDT"}, # America/Anchorage - "Tocantins Standard Time" => {"BRT", "BRT"}, # America/Araguaina - "Paraguay Standard Time" => {"PYT", "PYST"}, # America/Asuncion - "Bahia Standard Time" => {"BRT", "BRT"}, # America/Bahia - "SA Pacific Standard Time" => {"COT", "COT"}, # America/Bogota - "Argentina Standard Time" => {"ART", "ART"}, # America/Buenos_Aires + "Tocantins Standard Time" => {"-03", "-03"}, # America/Araguaina + "Paraguay Standard Time" => {"-04", "-03"}, # America/Asuncion + "Bahia Standard Time" => {"-03", "-03"}, # America/Bahia + "SA Pacific Standard Time" => {"-05", "-05"}, # America/Bogota + "Argentina Standard Time" => {"-03", "-03"}, # America/Buenos_Aires "Eastern Standard Time (Mexico)" => {"EST", "EST"}, # America/Cancun - "Venezuela Standard Time" => {"VET", "VET"}, # America/Caracas - "SA Eastern Standard Time" => {"GFT", "GFT"}, # America/Cayenne + "Venezuela Standard Time" => {"-04", "-04"}, # America/Caracas + "SA Eastern Standard Time" => {"-03", "-03"}, # America/Cayenne "Central Standard Time" => {"CST", "CDT"}, # America/Chicago - "Mountain Standard Time (Mexico)" => {"MST", "MDT"}, # America/Chihuahua - "Central Brazilian Standard Time" => {"AMT", "AMST"}, # America/Cuiaba + "Central Brazilian Standard Time" => {"-04", "-04"}, # America/Cuiaba "Mountain Standard Time" => {"MST", "MDT"}, # America/Denver - "Greenland Standard Time" => {"WGT", "WGST"}, # America/Godthab - "Turks And Caicos Standard Time" => {"AST", "AST"}, # America/Grand_Turk + "Greenland Standard Time" => {"-03", "-02"}, # America/Godthab + "Turks And Caicos Standard Time" => {"EST", "EDT"}, # America/Grand_Turk "Central America Standard Time" => {"CST", "CST"}, # America/Guatemala "Atlantic Standard Time" => {"AST", "ADT"}, # America/Halifax "Cuba Standard Time" => {"CST", "CDT"}, # America/Havana "US Eastern Standard Time" => {"EST", "EDT"}, # America/Indianapolis - "SA Western Standard Time" => {"BOT", "BOT"}, # America/La_Paz + "SA Western Standard Time" => {"-04", "-04"}, # America/La_Paz "Pacific Standard Time" => {"PST", "PDT"}, # America/Los_Angeles - "Central Standard Time (Mexico)" => {"CST", "CDT"}, # America/Mexico_City - "Saint Pierre Standard Time" => {"PMST", "PMDT"}, # America/Miquelon - "Montevideo Standard Time" => {"UYT", "UYT"}, # America/Montevideo + "Mountain Standard Time (Mexico)" => {"MST", "MST"}, # America/Mazatlan + "Central Standard Time (Mexico)" => {"CST", "CST"}, # America/Mexico_City + "Saint Pierre Standard Time" => {"-03", "-02"}, # America/Miquelon + "Montevideo Standard Time" => {"-03", "-03"}, # America/Montevideo "Eastern Standard Time" => {"EST", "EDT"}, # America/New_York "US Mountain Standard Time" => {"MST", "MST"}, # America/Phoenix - "Haiti Standard Time" => {"EST", "EST"}, # America/Port-au-Prince + "Haiti Standard Time" => {"EST", "EDT"}, # America/Port-au-Prince + "Magallanes Standard Time" => {"-03", "-03"}, # America/Punta_Arenas "Canada Central Standard Time" => {"CST", "CST"}, # America/Regina - "Pacific SA Standard Time" => {"CLT", "CLST"}, # America/Santiago - "E. South America Standard Time" => {"BRT", "BRST"}, # America/Sao_Paulo + "Pacific SA Standard Time" => {"-04", "-03"}, # America/Santiago + "E. South America Standard Time" => {"-03", "-03"}, # America/Sao_Paulo "Newfoundland Standard Time" => {"NST", "NDT"}, # America/St_Johns "Pacific Standard Time (Mexico)" => {"PST", "PDT"}, # America/Tijuana + "Yukon Standard Time" => {"MST", "MST"}, # America/Whitehorse "Central Asia Standard Time" => {"+06", "+06"}, # Asia/Almaty - "Jordan Standard Time" => {"EET", "EEST"}, # Asia/Amman - "Arabic Standard Time" => {"AST", "AST"}, # Asia/Baghdad + "Jordan Standard Time" => {"+03", "+03"}, # Asia/Amman + "Arabic Standard Time" => {"+03", "+03"}, # Asia/Baghdad "Azerbaijan Standard Time" => {"+04", "+04"}, # Asia/Baku - "SE Asia Standard Time" => {"ICT", "ICT"}, # Asia/Bangkok + "SE Asia Standard Time" => {"+07", "+07"}, # Asia/Bangkok "Altai Standard Time" => {"+07", "+07"}, # Asia/Barnaul "Middle East Standard Time" => {"EET", "EEST"}, # Asia/Beirut "India Standard Time" => {"IST", "IST"}, # Asia/Calcutta "Transbaikal Standard Time" => {"+09", "+09"}, # Asia/Chita "Sri Lanka Standard Time" => {"+0530", "+0530"}, # Asia/Colombo - "Syria Standard Time" => {"EET", "EEST"}, # Asia/Damascus - "Bangladesh Standard Time" => {"BDT", "BDT"}, # Asia/Dhaka - "Arabian Standard Time" => {"GST", "GST"}, # Asia/Dubai + "Syria Standard Time" => {"+03", "+03"}, # Asia/Damascus + "Bangladesh Standard Time" => {"+06", "+06"}, # Asia/Dhaka + "Arabian Standard Time" => {"+04", "+04"}, # Asia/Dubai "West Bank Standard Time" => {"EET", "EEST"}, # Asia/Hebron - "W. Mongolia Standard Time" => {"HOVT", "HOVST"}, # Asia/Hovd + "W. Mongolia Standard Time" => {"+07", "+07"}, # Asia/Hovd "North Asia East Standard Time" => {"+08", "+08"}, # Asia/Irkutsk "Israel Standard Time" => {"IST", "IDT"}, # Asia/Jerusalem - "Afghanistan Standard Time" => {"AFT", "AFT"}, # Asia/Kabul + "Afghanistan Standard Time" => {"+0430", "+0430"}, # Asia/Kabul "Russia Time Zone 11" => {"+12", "+12"}, # Asia/Kamchatka "Pakistan Standard Time" => {"PKT", "PKT"}, # Asia/Karachi - "Nepal Standard Time" => {"NPT", "NPT"}, # Asia/Katmandu + "Nepal Standard Time" => {"+0545", "+0545"}, # Asia/Katmandu "North Asia Standard Time" => {"+07", "+07"}, # Asia/Krasnoyarsk "Magadan Standard Time" => {"+11", "+11"}, # Asia/Magadan "N. Central Asia Standard Time" => {"+07", "+07"}, # Asia/Novosibirsk "Omsk Standard Time" => {"+06", "+06"}, # Asia/Omsk "North Korea Standard Time" => {"KST", "KST"}, # Asia/Pyongyang - "Myanmar Standard Time" => {"MMT", "MMT"}, # Asia/Rangoon - "Arab Standard Time" => {"AST", "AST"}, # Asia/Riyadh + "Qyzylorda Standard Time" => {"+05", "+05"}, # Asia/Qyzylorda + "Myanmar Standard Time" => {"+0630", "+0630"}, # Asia/Rangoon + "Arab Standard Time" => {"+03", "+03"}, # Asia/Riyadh "Sakhalin Standard Time" => {"+11", "+11"}, # Asia/Sakhalin "Korea Standard Time" => {"KST", "KST"}, # Asia/Seoul "China Standard Time" => {"CST", "CST"}, # Asia/Shanghai - "Singapore Standard Time" => {"SGT", "SGT"}, # Asia/Singapore + "Singapore Standard Time" => {"+08", "+08"}, # Asia/Singapore "Russia Time Zone 10" => {"+11", "+11"}, # Asia/Srednekolymsk "Taipei Standard Time" => {"CST", "CST"}, # Asia/Taipei "West Asia Standard Time" => {"+05", "+05"}, # Asia/Tashkent "Georgian Standard Time" => {"+04", "+04"}, # Asia/Tbilisi - "Iran Standard Time" => {"IRST", "IRDT"}, # Asia/Tehran + "Iran Standard Time" => {"+0330", "+0330"}, # Asia/Tehran "Tokyo Standard Time" => {"JST", "JST"}, # Asia/Tokyo "Tomsk Standard Time" => {"+07", "+07"}, # Asia/Tomsk - "Ulaanbaatar Standard Time" => {"ULAT", "ULAST"}, # Asia/Ulaanbaatar + "Ulaanbaatar Standard Time" => {"+08", "+08"}, # Asia/Ulaanbaatar "Vladivostok Standard Time" => {"+10", "+10"}, # Asia/Vladivostok "Yakutsk Standard Time" => {"+09", "+09"}, # Asia/Yakutsk "Ekaterinburg Standard Time" => {"+05", "+05"}, # Asia/Yekaterinburg "Caucasus Standard Time" => {"+04", "+04"}, # Asia/Yerevan - "Azores Standard Time" => {"AZOT", "AZOST"}, # Atlantic/Azores - "Cape Verde Standard Time" => {"CVT", "CVT"}, # Atlantic/Cape_Verde + "Azores Standard Time" => {"-01", "+00"}, # Atlantic/Azores + "Cape Verde Standard Time" => {"-01", "-01"}, # Atlantic/Cape_Verde "Greenwich Standard Time" => {"GMT", "GMT"}, # Atlantic/Reykjavik "Cen. Australia Standard Time" => {"ACST", "ACDT"}, # Australia/Adelaide "E. Australia Standard Time" => {"AEST", "AEST"}, # Australia/Brisbane "AUS Central Standard Time" => {"ACST", "ACST"}, # Australia/Darwin - "Aus Central W. Standard Time" => {"ACWST", "ACWST"}, # Australia/Eucla + "Aus Central W. Standard Time" => {"+0845", "+0845"}, # Australia/Eucla "Tasmania Standard Time" => {"AEST", "AEDT"}, # Australia/Hobart - "Lord Howe Standard Time" => {"LHST", "LHDT"}, # Australia/Lord_Howe + "Lord Howe Standard Time" => {"+1030", "+11"}, # Australia/Lord_Howe "W. Australia Standard Time" => {"AWST", "AWST"}, # Australia/Perth "AUS Eastern Standard Time" => {"AEST", "AEDT"}, # Australia/Sydney - "UTC" => {"GMT", "GMT"}, # Etc/GMT "UTC-11" => {"-11", "-11"}, # Etc/GMT+11 "Dateline Standard Time" => {"-12", "-12"}, # Etc/GMT+12 "UTC-02" => {"-02", "-02"}, # Etc/GMT+2 @@ -111,6 +116,7 @@ module Crystal::System::Time "UTC-09" => {"-09", "-09"}, # Etc/GMT+9 "UTC+12" => {"+12", "+12"}, # Etc/GMT-12 "UTC+13" => {"+13", "+13"}, # Etc/GMT-13 + "UTC" => {"UTC", "UTC"}, # Etc/UTC "Astrakhan Standard Time" => {"+04", "+04"}, # Europe/Astrakhan "W. Europe Standard Time" => {"CET", "CEST"}, # Europe/Berlin "GTB Standard Time" => {"EET", "EEST"}, # Europe/Bucharest @@ -125,21 +131,21 @@ module Crystal::System::Time "Romance Standard Time" => {"CET", "CEST"}, # Europe/Paris "Russia Time Zone 3" => {"+04", "+04"}, # Europe/Samara "Saratov Standard Time" => {"+04", "+04"}, # Europe/Saratov + "Volgograd Standard Time" => {"MSK", "MSK"}, # Europe/Volgograd "Central European Standard Time" => {"CET", "CEST"}, # Europe/Warsaw - "Mauritius Standard Time" => {"MUT", "MUT"}, # Indian/Mauritius - "Samoa Standard Time" => {"WSST", "WSDT"}, # Pacific/Apia + "Mauritius Standard Time" => {"+04", "+04"}, # Indian/Mauritius + "Samoa Standard Time" => {"+13", "+13"}, # Pacific/Apia "New Zealand Standard Time" => {"NZST", "NZDT"}, # Pacific/Auckland - "Bougainville Standard Time" => {"BST", "BST"}, # Pacific/Bougainville - "Chatham Islands Standard Time" => {"CHAST", "CHADT"}, # Pacific/Chatham - "Easter Island Standard Time" => {"EAST", "EASST"}, # Pacific/Easter - "Fiji Standard Time" => {"FJT", "FJST"}, # Pacific/Fiji - "Central Pacific Standard Time" => {"SBT", "SBT"}, # Pacific/Guadalcanal + "Bougainville Standard Time" => {"+11", "+11"}, # Pacific/Bougainville + "Chatham Islands Standard Time" => {"+1245", "+1345"}, # Pacific/Chatham + "Easter Island Standard Time" => {"-06", "-05"}, # Pacific/Easter + "Fiji Standard Time" => {"+12", "+12"}, # Pacific/Fiji + "Central Pacific Standard Time" => {"+11", "+11"}, # Pacific/Guadalcanal "Hawaiian Standard Time" => {"HST", "HST"}, # Pacific/Honolulu - "Line Islands Standard Time" => {"LINT", "LINT"}, # Pacific/Kiritimati - "Marquesas Standard Time" => {"MART", "MART"}, # Pacific/Marquesas - "Norfolk Standard Time" => {"NFT", "NFT"}, # Pacific/Norfolk - "West Pacific Standard Time" => {"PGT", "PGT"}, # Pacific/Port_Moresby - "Tonga Standard Time" => {"+13", "+14"}, # Pacific/Tongatapu - + "Line Islands Standard Time" => {"+14", "+14"}, # Pacific/Kiritimati + "Marquesas Standard Time" => {"-0930", "-0930"}, # Pacific/Marquesas + "Norfolk Standard Time" => {"+11", "+12"}, # Pacific/Norfolk + "West Pacific Standard Time" => {"+10", "+10"}, # Pacific/Port_Moresby + "Tonga Standard Time" => {"+13", "+13"}, # Pacific/Tongatapu } end