timezones.py 5.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import datetime
  2. from django.utils.translation import ugettext_lazy as _
  3. import pytz
  4. TIMEZONES = (
  5. ('Pacific/Apia', _('(UTC-13:00) Samoa'), _('(UTC-14:00) Samoa')),
  6. ('Pacific/Midway', _('(UTC-11:00) Midway Islands, American Samoa')),
  7. ('Pacific/Honolulu', _('(UTC-10:00) Cook Islands, Hawaii, Society Islands')),
  8. ('America/Adak', _('(UTC-10:00) Aleutian Islands'), _('(UTC-09:00) Aleutian Islands')),
  9. ('Pacific/Marquesas', _('(UTC-09:30) Marquesas Islands')),
  10. ('Pacific/Gambier', _('(UTC-09:00) Gambier Islands')),
  11. ('America/Anchorage', _('(UTC-09:00) Alaska Standard Time'), _('(UTC-08:00) Alaska Daylight Time')),
  12. ('Pacific/Pitcairn', _('(UTC-08:00) Pitcairn Islands')),
  13. ('America/Los_Angeles', _('(UTC-08:00) Pacific Time (Canada and US)'), _('(UTC-07:00) Pacific Time (Canada and US)')),
  14. ('America/Santa_Isabel', _('(UTC-08:00) Baja California'), _('(UTC-07:00) Baja California')),
  15. ('America/Phoenix', _('(UTC-07:00) Mountain Standard Time (No DST)')),
  16. ('America/Hermosillo', _('(UTC-07:00) Sonora')),
  17. ('America/Denver', _('(UTC-07:00) Mountain Standard Time'), _('(UTC-06:00) Mountain Summer Time')),
  18. ('America/Chihuahua', _('(UTC-07:00) Baja California Sur, Chihuahua, Nayarit, Sinaloa'), _('(UTC-06:00) Baja California Sur, Chihuahua, Nayarit, Sinaloa')),
  19. ('America/Costa_Rica', _('(UTC-06:00) Costa Rica, El Salvador, Galapagos, Guatemala, Managua')),
  20. ('America/Chicago', _('(UTC-06:00) Central Standard Time'), _('(UTC-05:00) Central Daylight Time')),
  21. ('America/Mexico_City', _('(UTC-06:00) Mexican Central Zone'), _('(UTC-05:00) Mexican Central Zone')),
  22. ('America/Panama', _('(UTC-05:00) Bogota, Cayman, Guayaquil, Jamaica, Lima, Panama')),
  23. ('America/New_York', _('(UTC-05:00) Eastern Standard Time'), _('(UTC-04:00) Eastern Daylight Time')),
  24. ('America/Caracas', _('(UTC-04:30) Caracas')),
  25. ('America/Puerto_Rico', _('(UTC-04:00) Barbados, Dominica, Puerto Rico, Santo Domingo')),
  26. ('America/Santiago', _('(UTC-04:00) Bermuda, Campo Grande, Goose Bay, Santiago, Thule'), _('(UTC-03:00) Bermuda, Campo Grande, Goose Bay, Santiago, Thule')),
  27. ('America/St_Johns', _('(UTC-03:30) Newfoundland Time')),
  28. ('America/Argentina/La_Rioja', _('(UTC-03:00) San Juan, San Luis, Santa Cruz')),
  29. ('America/Sao_Paulo', _('(UTC-03:00) Buenos Aires, Godthab, Sao Paulo, Montevideo'), _('(UTC-02:00) Buenos Aires, Godthab, Sao Paulo, Montevideo')),
  30. ('America/Noronha', _('(UTC-02:00) Atlantic islands')),
  31. ('Atlantic/Cape_Verde', _('(UTC-01:00) Cape Verde Time')),
  32. ('Atlantic/Azores', _('(UTC-01:00) Azores, Scoresbysund'), _('(UTC) Azores, Scoresbysund')),
  33. ('utc', _('(UTC) Coordinated Universal Time')),
  34. ('Africa/Dakar', _('(UTC) Dakar, Rabat')),
  35. ('Europe/Lisbon', _('(UTC) Western European Time'), _('(UTC+01:00) Western European Summer Time')),
  36. ('Africa/Algiers', _('(UTC+01:00) West Africa Time')),
  37. ('Europe/Zurich', _('(UTC+01:00) Central European Time'), _('(UTC+02:00) Central European Summer Time')),
  38. ('Africa/Cairo', _('(UTC+02:00) Central Africa Time')),
  39. ('Europe/Athens', _('(UTC+02:00) Eastern European Time'), _('(UTC+03:00) Eastern European Summer Time')),
  40. ('Asia/Qatar', _('(UTC+03:00) East Africa Time')),
  41. ('Europe/Minsk', _('(UTC+03:00) Further-eastern European Time')),
  42. ('Asia/Tehran', _('(UTC+03:30) Iran Time'), _('(UTC+04:30) Iran Time')),
  43. ('Europe/Moscow', _('(UTC+04:00) Moscow Standard Time, Georgia Standard Time')),
  44. ('Asia/Dubai', _('(UTC+04:00) United Arab Emirates Standard Time')),
  45. ('Asia/Baku', _('(UTC+05:00) Baku, Yerevan'), _('(UTC+06:00) Baku, Yerevan')),
  46. ('Asia/Kabul', _('(UTC+04:30) Afghanistan Standard Time')),
  47. ('Asia/Karachi', _('(UTC+05:00) Ashgabat, Dushanbe, Karachi, Maldives, Tashkent')),
  48. ('Asia/Kolkata', _('(UTC+05:30) Colombo, Kolkata')),
  49. ('Asia/Kathmandu', _('(UTC+05:45) Kathmandu')),
  50. ('Asia/Almaty', _('(UTC+06:00) Astana, Bishkek, Dhaka, Thimphu, Yekaterinburg')),
  51. ('Asia/Rangoon', _('(UTC+06:30) Yangon, Cocos Islands')),
  52. ('Asia/Bangkok', _('(UTC+07:00) Bangkok, Ho Chi Minh, Jakarta, Novosibirsk')),
  53. ('Asia/Taipei', _('(UTC+08:00) Beijing, Hong Kong, Kuala Lumpur, Singapore, Taipei')),
  54. ('Australia/Perth', _('(UTC+08:00) Australian Western Standard Time')),
  55. ('Australia/Eucla', _('(UTC+08:45) Eucla Area')),
  56. ('Asia/Tokyo', _('(UTC+09:00) Tokyo, Seoul, Irkutsk, Pyongyang')),
  57. ('Australia/Darwin', _('(UTC+09:30) Australian Central Standard Time')),
  58. ('Australia/Adelaide', _('(UTC+09:30) Australian Central Standard Time')),
  59. ('Australia/Melbourne', _('(UTC+10:00) Australian Eastern Standard Time'), _('(UTC+11:00) Australian Eastern Summer Time')),
  60. ('Australia/Lord_Howe', _('(UTC+10:30) Lord Howe Island'), _('(UTC+11:00) Lord Howe Island')),
  61. ('Pacific/Guadalcanal', _('(UTC+11:00) Guadalcanal, Honiara, Noumea, Vladivostok')),
  62. ('Pacific/Norfolk', _('(UTC+11:30) Norfolk Island')),
  63. ('Pacific/Wake', _('(UTC+12:00) Kamchatka, Marshall Islands')),
  64. ('Pacific/Auckland', _('(UTC+12:00) Auckland, Fiji'), _('(UTC+13:00) Auckland, Fiji')),
  65. ('Pacific/Chatham', _('(UTC+12:45) Chatham Islands'), _('(UTC+13:45) Chatham Islands')),
  66. ('Pacific/Enderbury', _('(UTC+13:00) Phoenix Islands')),
  67. ('Pacific/Kiritimati', _('(UTC+14:00) Nuku\'alofa')),
  68. )
  69. def choices():
  70. """
  71. Generate user-friendly timezone list for selects
  72. """
  73. utc_now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
  74. ready_list = []
  75. for tz in TIMEZONES:
  76. if len(tz) == 3:
  77. tzinfo = pytz.timezone(tz[0])
  78. if utc_now.astimezone(tzinfo).dst().seconds > 0:
  79. ready_list.append((tz[0], tz[2]))
  80. else:
  81. ready_list.append((tz[0], tz[1]))
  82. else:
  83. ready_list.append(tz)
  84. return tuple(ready_list)