Skip to content

Instantly share code, notes, and snippets.

@pedrocarmona
Last active March 8, 2018 11:40
Show Gist options
  • Save pedrocarmona/f41d25e631c1144045971c319f1c9e17 to your computer and use it in GitHub Desktop.
Save pedrocarmona/f41d25e631c1144045971c319f1c9e17 to your computer and use it in GitHub Desktop.
Time Zone Enum Type graphql-ruby
Types::TimeZoneEnumType = GraphQL::EnumType.define do
name "TimeZoneEnum"
ActiveSupport::TimeZone.all.uniq! {|tz| tz.tzinfo.identifier }.map { |tz|
symbol = tz.tzinfo.identifier.gsub(/[^_a-zA-Z0-9]/, '_').squeeze('_').upcase!
value("TZ_#{symbol}", tz.tzinfo.identifier, value: tz.name)
}
end
@pedrocarmona
Copy link
Author

pedrocarmona commented Mar 6, 2018

Query to check the values:

query timeZones{
  __type(name: "TimeZoneEnum") {
    enumValues {
      name
      description
    }
  }
}

Result:

{
  "data": {
    "__type": {
      "enumValues": [
        {
          "name": "TZ_PACIFIC_PAGO_PAGO",
          "description": "Pacific/Pago_Pago"
        },
        {
          "name": "TZ_PACIFIC_MIDWAY",
          "description": "Pacific/Midway"
        },
        {
          "name": "TZ_PACIFIC_HONOLULU",
          "description": "Pacific/Honolulu"
        },
        {
          "name": "TZ_AMERICA_JUNEAU",
          "description": "America/Juneau"
        },
        {
          "name": "TZ_AMERICA_LOS_ANGELES",
          "description": "America/Los_Angeles"
        },
        {
          "name": "TZ_AMERICA_TIJUANA",
          "description": "America/Tijuana"
        },
        {
          "name": "TZ_AMERICA_PHOENIX",
          "description": "America/Phoenix"
        },
        {
          "name": "TZ_AMERICA_CHIHUAHUA",
          "description": "America/Chihuahua"
        },
        {
          "name": "TZ_AMERICA_MAZATLAN",
          "description": "America/Mazatlan"
        },
        {
          "name": "TZ_AMERICA_DENVER",
          "description": "America/Denver"
        },
        {
          "name": "TZ_AMERICA_GUATEMALA",
          "description": "America/Guatemala"
        },
        {
          "name": "TZ_AMERICA_CHICAGO",
          "description": "America/Chicago"
        },
        {
          "name": "TZ_AMERICA_MEXICO_CITY",
          "description": "America/Mexico_City"
        },
        {
          "name": "TZ_AMERICA_MONTERREY",
          "description": "America/Monterrey"
        },
        {
          "name": "TZ_AMERICA_REGINA",
          "description": "America/Regina"
        },
        {
          "name": "TZ_AMERICA_BOGOTA",
          "description": "America/Bogota"
        },
        {
          "name": "TZ_AMERICA_NEW_YORK",
          "description": "America/New_York"
        },
        {
          "name": "TZ_AMERICA_INDIANA_INDIANAPOLIS",
          "description": "America/Indiana/Indianapolis"
        },
        {
          "name": "TZ_AMERICA_LIMA",
          "description": "America/Lima"
        },
        {
          "name": "TZ_AMERICA_HALIFAX",
          "description": "America/Halifax"
        },
        {
          "name": "TZ_AMERICA_CARACAS",
          "description": "America/Caracas"
        },
        {
          "name": "TZ_AMERICA_GUYANA",
          "description": "America/Guyana"
        },
        {
          "name": "TZ_AMERICA_LA_PAZ",
          "description": "America/La_Paz"
        },
        {
          "name": "TZ_AMERICA_SANTIAGO",
          "description": "America/Santiago"
        },
        {
          "name": "TZ_AMERICA_ST_JOHNS",
          "description": "America/St_Johns"
        },
        {
          "name": "TZ_AMERICA_SAO_PAULO",
          "description": "America/Sao_Paulo"
        },
        {
          "name": "TZ_AMERICA_ARGENTINA_BUENOS_AIRES",
          "description": "America/Argentina/Buenos_Aires"
        },
        {
          "name": "TZ_AMERICA_GODTHAB",
          "description": "America/Godthab"
        },
        {
          "name": "TZ_AMERICA_MONTEVIDEO",
          "description": "America/Montevideo"
        },
        {
          "name": "TZ_ATLANTIC_SOUTH_GEORGIA",
          "description": "Atlantic/South_Georgia"
        },
        {
          "name": "TZ_ATLANTIC_AZORES",
          "description": "Atlantic/Azores"
        },
        {
          "name": "TZ_ATLANTIC_CAPE_VERDE",
          "description": "Atlantic/Cape_Verde"
        },
        {
          "name": "TZ_AFRICA_CASABLANCA",
          "description": "Africa/Casablanca"
        },
        {
          "name": "TZ_EUROPE_DUBLIN",
          "description": "Europe/Dublin"
        },
        {
          "name": "TZ_EUROPE_LONDON",
          "description": "Europe/London"
        },
        {
          "name": "TZ_EUROPE_LISBON",
          "description": "Europe/Lisbon"
        },
        {
          "name": "TZ_AFRICA_MONROVIA",
          "description": "Africa/Monrovia"
        },
        {
          "name": "TZ_ETC_UTC",
          "description": "Etc/UTC"
        },
        {
          "name": "TZ_EUROPE_AMSTERDAM",
          "description": "Europe/Amsterdam"
        },
        {
          "name": "TZ_EUROPE_BELGRADE",
          "description": "Europe/Belgrade"
        },
        {
          "name": "TZ_EUROPE_BERLIN",
          "description": "Europe/Berlin"
        },
        {
          "name": "TZ_EUROPE_ZURICH",
          "description": "Europe/Zurich"
        },
        {
          "name": "TZ_EUROPE_BRATISLAVA",
          "description": "Europe/Bratislava"
        },
        {
          "name": "TZ_EUROPE_BRUSSELS",
          "description": "Europe/Brussels"
        },
        {
          "name": "TZ_EUROPE_BUDAPEST",
          "description": "Europe/Budapest"
        },
        {
          "name": "TZ_EUROPE_COPENHAGEN",
          "description": "Europe/Copenhagen"
        },
        {
          "name": "TZ_EUROPE_LJUBLJANA",
          "description": "Europe/Ljubljana"
        },
        {
          "name": "TZ_EUROPE_MADRID",
          "description": "Europe/Madrid"
        },
        {
          "name": "TZ_EUROPE_PARIS",
          "description": "Europe/Paris"
        },
        {
          "name": "TZ_EUROPE_PRAGUE",
          "description": "Europe/Prague"
        },
        {
          "name": "TZ_EUROPE_ROME",
          "description": "Europe/Rome"
        },
        {
          "name": "TZ_EUROPE_SARAJEVO",
          "description": "Europe/Sarajevo"
        },
        {
          "name": "TZ_EUROPE_SKOPJE",
          "description": "Europe/Skopje"
        },
        {
          "name": "TZ_EUROPE_STOCKHOLM",
          "description": "Europe/Stockholm"
        },
        {
          "name": "TZ_EUROPE_VIENNA",
          "description": "Europe/Vienna"
        },
        {
          "name": "TZ_EUROPE_WARSAW",
          "description": "Europe/Warsaw"
        },
        {
          "name": "TZ_AFRICA_ALGIERS",
          "description": "Africa/Algiers"
        },
        {
          "name": "TZ_EUROPE_ZAGREB",
          "description": "Europe/Zagreb"
        },
        {
          "name": "TZ_EUROPE_ATHENS",
          "description": "Europe/Athens"
        },
        {
          "name": "TZ_EUROPE_BUCHAREST",
          "description": "Europe/Bucharest"
        },
        {
          "name": "TZ_AFRICA_CAIRO",
          "description": "Africa/Cairo"
        },
        {
          "name": "TZ_AFRICA_HARARE",
          "description": "Africa/Harare"
        },
        {
          "name": "TZ_EUROPE_HELSINKI",
          "description": "Europe/Helsinki"
        },
        {
          "name": "TZ_ASIA_JERUSALEM",
          "description": "Asia/Jerusalem"
        },
        {
          "name": "TZ_EUROPE_KALININGRAD",
          "description": "Europe/Kaliningrad"
        },
        {
          "name": "TZ_EUROPE_KIEV",
          "description": "Europe/Kiev"
        },
        {
          "name": "TZ_AFRICA_JOHANNESBURG",
          "description": "Africa/Johannesburg"
        },
        {
          "name": "TZ_EUROPE_RIGA",
          "description": "Europe/Riga"
        },
        {
          "name": "TZ_EUROPE_SOFIA",
          "description": "Europe/Sofia"
        },
        {
          "name": "TZ_EUROPE_TALLINN",
          "description": "Europe/Tallinn"
        },
        {
          "name": "TZ_EUROPE_VILNIUS",
          "description": "Europe/Vilnius"
        },
        {
          "name": "TZ_ASIA_BAGHDAD",
          "description": "Asia/Baghdad"
        },
        {
          "name": "TZ_EUROPE_ISTANBUL",
          "description": "Europe/Istanbul"
        },
        {
          "name": "TZ_ASIA_KUWAIT",
          "description": "Asia/Kuwait"
        },
        {
          "name": "TZ_EUROPE_MINSK",
          "description": "Europe/Minsk"
        },
        {
          "name": "TZ_EUROPE_MOSCOW",
          "description": "Europe/Moscow"
        },
        {
          "name": "TZ_AFRICA_NAIROBI",
          "description": "Africa/Nairobi"
        },
        {
          "name": "TZ_ASIA_RIYADH",
          "description": "Asia/Riyadh"
        },
        {
          "name": "TZ_EUROPE_VOLGOGRAD",
          "description": "Europe/Volgograd"
        },
        {
          "name": "TZ_ASIA_TEHRAN",
          "description": "Asia/Tehran"
        },
        {
          "name": "TZ_ASIA_MUSCAT",
          "description": "Asia/Muscat"
        },
        {
          "name": "TZ_ASIA_BAKU",
          "description": "Asia/Baku"
        },
        {
          "name": "TZ_EUROPE_SAMARA",
          "description": "Europe/Samara"
        },
        {
          "name": "TZ_ASIA_TBILISI",
          "description": "Asia/Tbilisi"
        },
        {
          "name": "TZ_ASIA_YEREVAN",
          "description": "Asia/Yerevan"
        },
        {
          "name": "TZ_ASIA_KABUL",
          "description": "Asia/Kabul"
        },
        {
          "name": "TZ_ASIA_YEKATERINBURG",
          "description": "Asia/Yekaterinburg"
        },
        {
          "name": "TZ_ASIA_KARACHI",
          "description": "Asia/Karachi"
        },
        {
          "name": "TZ_ASIA_TASHKENT",
          "description": "Asia/Tashkent"
        },
        {
          "name": "TZ_ASIA_KOLKATA",
          "description": "Asia/Kolkata"
        },
        {
          "name": "TZ_ASIA_COLOMBO",
          "description": "Asia/Colombo"
        },
        {
          "name": "TZ_ASIA_KATHMANDU",
          "description": "Asia/Kathmandu"
        },
        {
          "name": "TZ_ASIA_ALMATY",
          "description": "Asia/Almaty"
        },
        {
          "name": "TZ_ASIA_DHAKA",
          "description": "Asia/Dhaka"
        },
        {
          "name": "TZ_ASIA_URUMQI",
          "description": "Asia/Urumqi"
        },
        {
          "name": "TZ_ASIA_RANGOON",
          "description": "Asia/Rangoon"
        },
        {
          "name": "TZ_ASIA_BANGKOK",
          "description": "Asia/Bangkok"
        },
        {
          "name": "TZ_ASIA_JAKARTA",
          "description": "Asia/Jakarta"
        },
        {
          "name": "TZ_ASIA_KRASNOYARSK",
          "description": "Asia/Krasnoyarsk"
        },
        {
          "name": "TZ_ASIA_NOVOSIBIRSK",
          "description": "Asia/Novosibirsk"
        },
        {
          "name": "TZ_ASIA_SHANGHAI",
          "description": "Asia/Shanghai"
        },
        {
          "name": "TZ_ASIA_CHONGQING",
          "description": "Asia/Chongqing"
        },
        {
          "name": "TZ_ASIA_HONG_KONG",
          "description": "Asia/Hong_Kong"
        },
        {
          "name": "TZ_ASIA_IRKUTSK",
          "description": "Asia/Irkutsk"
        },
        {
          "name": "TZ_ASIA_KUALA_LUMPUR",
          "description": "Asia/Kuala_Lumpur"
        },
        {
          "name": "TZ_AUSTRALIA_PERTH",
          "description": "Australia/Perth"
        },
        {
          "name": "TZ_ASIA_SINGAPORE",
          "description": "Asia/Singapore"
        },
        {
          "name": "TZ_ASIA_TAIPEI",
          "description": "Asia/Taipei"
        },
        {
          "name": "TZ_ASIA_ULAANBAATAR",
          "description": "Asia/Ulaanbaatar"
        },
        {
          "name": "TZ_ASIA_TOKYO",
          "description": "Asia/Tokyo"
        },
        {
          "name": "TZ_ASIA_SEOUL",
          "description": "Asia/Seoul"
        },
        {
          "name": "TZ_ASIA_YAKUTSK",
          "description": "Asia/Yakutsk"
        },
        {
          "name": "TZ_AUSTRALIA_ADELAIDE",
          "description": "Australia/Adelaide"
        },
        {
          "name": "TZ_AUSTRALIA_DARWIN",
          "description": "Australia/Darwin"
        },
        {
          "name": "TZ_AUSTRALIA_BRISBANE",
          "description": "Australia/Brisbane"
        },
        {
          "name": "TZ_AUSTRALIA_MELBOURNE",
          "description": "Australia/Melbourne"
        },
        {
          "name": "TZ_PACIFIC_GUAM",
          "description": "Pacific/Guam"
        },
        {
          "name": "TZ_AUSTRALIA_HOBART",
          "description": "Australia/Hobart"
        },
        {
          "name": "TZ_PACIFIC_PORT_MORESBY",
          "description": "Pacific/Port_Moresby"
        },
        {
          "name": "TZ_AUSTRALIA_SYDNEY",
          "description": "Australia/Sydney"
        },
        {
          "name": "TZ_ASIA_VLADIVOSTOK",
          "description": "Asia/Vladivostok"
        },
        {
          "name": "TZ_ASIA_MAGADAN",
          "description": "Asia/Magadan"
        },
        {
          "name": "TZ_PACIFIC_NOUMEA",
          "description": "Pacific/Noumea"
        },
        {
          "name": "TZ_PACIFIC_GUADALCANAL",
          "description": "Pacific/Guadalcanal"
        },
        {
          "name": "TZ_ASIA_SREDNEKOLYMSK",
          "description": "Asia/Srednekolymsk"
        },
        {
          "name": "TZ_PACIFIC_AUCKLAND",
          "description": "Pacific/Auckland"
        },
        {
          "name": "TZ_PACIFIC_FIJI",
          "description": "Pacific/Fiji"
        },
        {
          "name": "TZ_ASIA_KAMCHATKA",
          "description": "Asia/Kamchatka"
        },
        {
          "name": "TZ_PACIFIC_MAJURO",
          "description": "Pacific/Majuro"
        },
        {
          "name": "TZ_PACIFIC_CHATHAM",
          "description": "Pacific/Chatham"
        },
        {
          "name": "TZ_PACIFIC_TONGATAPU",
          "description": "Pacific/Tongatapu"
        },
        {
          "name": "TZ_PACIFIC_APIA",
          "description": "Pacific/Apia"
        },
        {
          "name": "TZ_PACIFIC_FAKAOFO",
          "description": "Pacific/Fakaofo"
        }
      ]
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment