Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezone conversions #458

Open
drewish opened this issue Nov 15, 2018 · 0 comments
Open

Timezone conversions #458

drewish opened this issue Nov 15, 2018 · 0 comments
Labels

Comments

@drewish
Copy link
Contributor

drewish commented Nov 15, 2018

I spent some time using a .Net timezone conversion library to convert its list of Windows timezones into a mapping of Windows to IANA timezones, then did the munging to get the Windows names into Xero's format (windows_tz_name.upcase.tr('. -', '')).

Here's the hash:

# Maps Zero's time zone names (`windows_tz_name.upcase.tr('. -', '')`) to the
# IANA time zone names.
TIME_ZONES = {
  "AFGHANISTANSTANDARDTIME" => "Asia/Kabul", "ALASKANSTANDARDTIME" => "America/Anchorage",
  "ALEUTIANSTANDARDTIME" => "America/Adak", "ALTAISTANDARDTIME" => "Asia/Barnaul",
  "ARABSTANDARDTIME" => "Asia/Riyadh", "ARABIANSTANDARDTIME" => "Asia/Dubai", "ARABICSTANDARDTIME" => "Asia/Baghdad",
  "ARGENTINASTANDARDTIME" => "America/Argentina/Buenos_Aires", "ASTRAKHANSTANDARDTIME" => "Europe/Astrakhan",
  "ATLANTICSTANDARDTIME" => "America/Halifax", "AUSCENTRALSTANDARDTIME" => "Australia/Darwin",
  "AUSCENTRALWSTANDARDTIME" => "Australia/Eucla", "AUSEASTERNSTANDARDTIME" => "Australia/Sydney",
  "AZERBAIJANSTANDARDTIME" => "Asia/Baku", "AZORESSTANDARDTIME" => "Atlantic/Azores",
  "BAHIASTANDARDTIME" => "America/Bahia", "BANGLADESHSTANDARDTIME" => "Asia/Dhaka",
  "BELARUSSTANDARDTIME" => "Europe/Minsk", "BOUGAINVILLESTANDARDTIME" => "Pacific/Bougainville",
  "CANADACENTRALSTANDARDTIME" => "America/Regina", "CAPEVERDESTANDARDTIME" => "Atlantic/Cape_Verde",
  "CAUCASUSSTANDARDTIME" => "Asia/Yerevan", "CENAUSTRALIASTANDARDTIME" => "Australia/Adelaide",
  "CENTRALAMERICASTANDARDTIME" => "America/Guatemala", "CENTRALASIASTANDARDTIME" => "Asia/Almaty",
  "CENTRALBRAZILIANSTANDARDTIME" => "America/Cuiaba", "CENTRALEUROPESTANDARDTIME" => "Europe/Budapest",
  "CENTRALEUROPEANSTANDARDTIME" => "Europe/Warsaw", "CENTRALPACIFICSTANDARDTIME" => "Pacific/Guadalcanal",
  "CENTRALSTANDARDTIME" => "America/Chicago", "CENTRALSTANDARDTIME(MEXICO)" => "America/Mexico_City",
  "CHATHAMISLANDSSTANDARDTIME" => "Pacific/Chatham", "CHINASTANDARDTIME" => "Asia/Shanghai",
  "CUBASTANDARDTIME" => "America/Havana", "DATELINESTANDARDTIME" => "Etc/GMT+12",
  "EAFRICASTANDARDTIME" => "Africa/Nairobi", "EAUSTRALIASTANDARDTIME" => "Australia/Brisbane",
  "EEUROPESTANDARDTIME" => "Europe/Chisinau", "ESOUTHAMERICASTANDARDTIME" => "America/Sao_Paulo",
  "EASTERISLANDSTANDARDTIME" => "Pacific/Easter", "EASTERNSTANDARDTIME" => "America/New_York",
  "EASTERNSTANDARDTIME(MEXICO)" => "America/Cancun", "EGYPTSTANDARDTIME" => "Africa/Cairo",
  "EKATERINBURGSTANDARDTIME" => "Asia/Yekaterinburg", "FIJISTANDARDTIME" => "Pacific/Fiji",
  "FLESTANDARDTIME" => "Europe/Kiev", "GEORGIANSTANDARDTIME" => "Asia/Tbilisi", "GMTSTANDARDTIME" => "Europe/London",
  "GREENLANDSTANDARDTIME" => "America/Godthab", "GREENWICHSTANDARDTIME" => "Atlantic/Reykjavik",
  "GTBSTANDARDTIME" => "Europe/Bucharest", "HAITISTANDARDTIME" => "America/Port-au-Prince",
  "HAWAIIANSTANDARDTIME" => "Pacific/Honolulu", "INDIASTANDARDTIME" => "Asia/Kolkata",
  "IRANSTANDARDTIME" => "Asia/Tehran", "ISRAELSTANDARDTIME" => "Asia/Jerusalem",
  "JORDANSTANDARDTIME" => "Asia/Amman", "KALININGRADSTANDARDTIME" => "Europe/Kaliningrad",
  "KAMCHATKASTANDARDTIME" => "Asia/Kamchatka", "KOREASTANDARDTIME" => "Asia/Seoul",
  "LIBYASTANDARDTIME" => "Africa/Tripoli", "LINEISLANDSSTANDARDTIME" => "Pacific/Kiritimati",
  "LORDHOWESTANDARDTIME" => "Australia/Lord_Howe", "MAGADANSTANDARDTIME" => "Asia/Magadan",
  "MAGALLANESSTANDARDTIME" => "America/Punta_Arenas", "MARQUESASSTANDARDTIME" => "Pacific/Marquesas",
  "MAURITIUSSTANDARDTIME" => "Indian/Mauritius", "MIDATLANTICSTANDARDTIME" => "Etc/GMT+2",
  "MIDDLEEASTSTANDARDTIME" => "Asia/Beirut", "MONTEVIDEOSTANDARDTIME" => "America/Montevideo",
  "MOROCCOSTANDARDTIME" => "Africa/Casablanca", "MOUNTAINSTANDARDTIME" => "America/Denver",
  "MOUNTAINSTANDARDTIME(MEXICO)" => "America/Chihuahua", "MYANMARSTANDARDTIME" => "Asia/Yangon",
  "NCENTRALASIASTANDARDTIME" => "Asia/Novosibirsk", "NAMIBIASTANDARDTIME" => "Africa/Windhoek",
  "NEPALSTANDARDTIME" => "Asia/Kathmandu", "NEWZEALANDSTANDARDTIME" => "Pacific/Auckland",
  "NEWFOUNDLANDSTANDARDTIME" => "America/St_Johns", "NORFOLKSTANDARDTIME" => "Pacific/Norfolk",
  "NORTHASIAEASTSTANDARDTIME" => "Asia/Irkutsk", "NORTHASIASTANDARDTIME" => "Asia/Krasnoyarsk",
  "NORTHKOREASTANDARDTIME" => "Asia/Pyongyang", "OMSKSTANDARDTIME" => "Asia/Omsk",
  "PACIFICSASTANDARDTIME" => "America/Santiago", "PACIFICSTANDARDTIME" => "America/Los_Angeles",
  "PACIFICSTANDARDTIME(MEXICO)" => "America/Tijuana", "PAKISTANSTANDARDTIME" => "Asia/Karachi",
  "PARAGUAYSTANDARDTIME" => "America/Asuncion", "ROMANCESTANDARDTIME" => "Europe/Paris",
  "RUSSIATIMEZONE10" => "Asia/Srednekolymsk", "RUSSIATIMEZONE11" => "Asia/Kamchatka",
  "RUSSIATIMEZONE3" => "Europe/Samara", "RUSSIANSTANDARDTIME" => "Europe/Moscow",
  "SAEASTERNSTANDARDTIME" => "America/Cayenne", "SAPACIFICSTANDARDTIME" => "America/Bogota",
  "SAWESTERNSTANDARDTIME" => "America/La_Paz", "SAINTPIERRESTANDARDTIME" => "America/Miquelon",
  "SAKHALINSTANDARDTIME" => "Asia/Sakhalin", "SAMOASTANDARDTIME" => "Pacific/Apia",
  "SAOTOMESTANDARDTIME" => "Africa/Sao_Tome", "SARATOVSTANDARDTIME" => "Europe/Saratov",
  "SEASIASTANDARDTIME" => "Asia/Bangkok", "SINGAPORESTANDARDTIME" => "Asia/Singapore",
  "SOUTHAFRICASTANDARDTIME" => "Africa/Johannesburg", "SRILANKASTANDARDTIME" => "Asia/Colombo",
  "SUDANSTANDARDTIME" => "Africa/Khartoum", "SYRIASTANDARDTIME" => "Asia/Damascus",
  "TAIPEISTANDARDTIME" => "Asia/Taipei", "TASMANIASTANDARDTIME" => "Australia/Hobart",
  "TOCANTINSSTANDARDTIME" => "America/Araguaina", "TOKYOSTANDARDTIME" => "Asia/Tokyo",
  "TOMSKSTANDARDTIME" => "Asia/Tomsk", "TONGASTANDARDTIME" => "Pacific/Tongatapu",
  "TRANSBAIKALSTANDARDTIME" => "Asia/Chita", "TURKEYSTANDARDTIME" => "Europe/Istanbul",
  "TURKSANDCAICOSSTANDARDTIME" => "America/Grand_Turk", "ULAANBAATARSTANDARDTIME" => "Asia/Ulaanbaatar",
  "USEASTERNSTANDARDTIME" => "America/Indiana/Indianapolis", "USMOUNTAINSTANDARDTIME" => "America/Phoenix",
  "UTC" => "Etc/UTC", "UTC+12" => "Etc/GMT+12", "UTC+13" => "Etc/GMT+13", "UTC02" => "Etc/GMT-2",
  "UTC08" => "Etc/GMT-8", "UTC09" => "Etc/GMT-9", "UTC11" => "Etc/GMT-11",
  "VENEZUELASTANDARDTIME" => "America/Caracas", "VLADIVOSTOKSTANDARDTIME" => "Asia/Vladivostok",
  "WAUSTRALIASTANDARDTIME" => "Australia/Perth", "WCENTRALAFRICASTANDARDTIME" => "Africa/Lagos",
  "WEUROPESTANDARDTIME" => "Europe/Berlin", "WMONGOLIASTANDARDTIME" => "Asia/Hovd",
  "WESTASIASTANDARDTIME" => "Asia/Tashkent", "WESTBANKSTANDARDTIME" => "Asia/Hebron",
  "WESTPACIFICSTANDARDTIME" => "Pacific/Port_Moresby", "YAKUTSKSTANDARDTIME" => "Asia/Yakutsk"
}.freeze

If there's any interest in including this with the gem I'm happy to open up a PR.

timezone = xero.Organisation.all.first.timezone # => "EASTERNSTANDARDTIME"
Time.parse("2017-08-31T17:24:48Z").in_time_zone(TIMEZONES[timezone]) # => Thu, 31 Aug 2017 13:24:48 EDT -04:00

It's very helpful for getting an invoice marked as due on the right date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants