upgrade tzlocal to v1.4

This commit is contained in:
Alan Hamlett 2017-09-05 09:47:50 -07:00
parent 7be37e55d8
commit 1c80ec9834
10 changed files with 106 additions and 34 deletions

View file

@ -2,23 +2,45 @@ from __future__ import with_statement
import os
import pytz
import subprocess
import sys
_cache_tz = None
if sys.version_info[0] == 2:
def _get_localzone():
pipe = subprocess.Popen(
class Popen(subprocess.Popen):
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
if self.stdout:
self.stdout.close()
if self.stderr:
self.stderr.close()
if self.stdin:
self.stdin.close()
# Wait for the process to terminate, to avoid zombies.
self.wait()
else:
from subprocess import Popen
def _get_localzone(_root='/'):
with Popen(
"systemsetup -gettimezone",
shell=True,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE
)
tzname = pipe.stdout.read().replace(b'Time Zone: ', b'').strip()
) as pipe:
tzname = pipe.stdout.read().replace(b'Time Zone: ', b'').strip()
if not tzname or tzname not in pytz.all_timezones_set:
# link will be something like /usr/share/zoneinfo/America/Los_Angeles.
link = os.readlink("/etc/localtime")
link = os.readlink(os.path.join(_root, "etc/localtime"))
tzname = link[link.rfind("zoneinfo/") + 9:]
return pytz.timezone(tzname)

Binary file not shown.

View file

@ -0,0 +1 @@
Africa/Harare

View file

@ -0,0 +1 @@
TIMEZONE = "Africa/Harare"

View file

@ -0,0 +1 @@
ZONE="Africa/Harare"

View file

@ -44,21 +44,22 @@ def _get_localzone(_root='/'):
# Now look for distribution specific configuration files
# that contain the timezone name.
tzpath = os.path.join(_root, 'etc/timezone')
if os.path.exists(tzpath):
with open(tzpath, 'rb') as tzfile:
data = tzfile.read()
for configfile in ('etc/timezone', 'var/db/zoneinfo'):
tzpath = os.path.join(_root, configfile)
if os.path.exists(tzpath):
with open(tzpath, 'rb') as tzfile:
data = tzfile.read()
# Issue #3 was that /etc/timezone was a zoneinfo file.
# That's a misconfiguration, but we need to handle it gracefully:
if data[:5] != 'TZif2':
etctz = data.strip().decode()
# Get rid of host definitions and comments:
if ' ' in etctz:
etctz, dummy = etctz.split(' ', 1)
if '#' in etctz:
etctz, dummy = etctz.split('#', 1)
return pytz.timezone(etctz.replace(' ', '_'))
# Issue #3 was that /etc/timezone was a zoneinfo file.
# That's a misconfiguration, but we need to handle it gracefully:
if data[:5] != 'TZif2':
etctz = data.strip().decode()
# Get rid of host definitions and comments:
if ' ' in etctz:
etctz, dummy = etctz.split(' ', 1)
if '#' in etctz:
etctz, dummy = etctz.split('#', 1)
return pytz.timezone(etctz.replace(' ', '_'))
# CentOS has a ZONE setting in /etc/sysconfig/clock,
# OpenSUSE has a TIMEZONE setting in /etc/sysconfig/clock and

View file

@ -4,16 +4,21 @@ win_tz = {'AUS Central Standard Time': 'Australia/Darwin',
'AUS Eastern Standard Time': 'Australia/Sydney',
'Afghanistan Standard Time': 'Asia/Kabul',
'Alaskan Standard Time': 'America/Anchorage',
'Aleutian Standard Time': 'America/Adak',
'Altai Standard Time': 'Asia/Barnaul',
'Arab Standard Time': 'Asia/Riyadh',
'Arabian Standard Time': 'Asia/Dubai',
'Arabic Standard Time': 'Asia/Baghdad',
'Argentina Standard Time': 'America/Buenos_Aires',
'Astrakhan Standard Time': 'Europe/Astrakhan',
'Atlantic Standard Time': 'America/Halifax',
'Aus Central W. Standard Time': 'Australia/Eucla',
'Azerbaijan Standard Time': 'Asia/Baku',
'Azores Standard Time': 'Atlantic/Azores',
'Bahia Standard Time': 'America/Bahia',
'Bangladesh Standard Time': 'Asia/Dhaka',
'Belarus Standard Time': 'Europe/Minsk',
'Bougainville Standard Time': 'Pacific/Bougainville',
'Canada Central Standard Time': 'America/Regina',
'Cape Verde Standard Time': 'Atlantic/Cape_Verde',
'Caucasus Standard Time': 'Asia/Yerevan',
@ -26,12 +31,15 @@ win_tz = {'AUS Central Standard Time': 'Australia/Darwin',
'Central Pacific Standard Time': 'Pacific/Guadalcanal',
'Central Standard Time': 'America/Chicago',
'Central Standard Time (Mexico)': 'America/Mexico_City',
'Chatham Islands Standard Time': 'Pacific/Chatham',
'China Standard Time': 'Asia/Shanghai',
'Cuba Standard Time': 'America/Havana',
'Dateline Standard Time': 'Etc/GMT+12',
'E. Africa Standard Time': 'Africa/Nairobi',
'E. Australia Standard Time': 'Australia/Brisbane',
'E. Europe Standard Time': 'Europe/Chisinau',
'E. South America Standard Time': 'America/Sao_Paulo',
'Easter Island Standard Time': 'Pacific/Easter',
'Eastern Standard Time': 'America/New_York',
'Eastern Standard Time (Mexico)': 'America/Cancun',
'Egypt Standard Time': 'Africa/Cairo',
@ -43,6 +51,7 @@ win_tz = {'AUS Central Standard Time': 'Australia/Darwin',
'Georgian Standard Time': 'Asia/Tbilisi',
'Greenland Standard Time': 'America/Godthab',
'Greenwich Standard Time': 'Atlantic/Reykjavik',
'Haiti Standard Time': 'America/Port-au-Prince',
'Hawaiian Standard Time': 'Pacific/Honolulu',
'India Standard Time': 'Asia/Calcutta',
'Iran Standard Time': 'Asia/Tehran',
@ -52,7 +61,9 @@ win_tz = {'AUS Central Standard Time': 'Australia/Darwin',
'Korea Standard Time': 'Asia/Seoul',
'Libya Standard Time': 'Africa/Tripoli',
'Line Islands Standard Time': 'Pacific/Kiritimati',
'Lord Howe Standard Time': 'Australia/Lord_Howe',
'Magadan Standard Time': 'Asia/Magadan',
'Marquesas Standard Time': 'Pacific/Marquesas',
'Mauritius Standard Time': 'Indian/Mauritius',
'Middle East Standard Time': 'Asia/Beirut',
'Montevideo Standard Time': 'America/Montevideo',
@ -65,11 +76,14 @@ win_tz = {'AUS Central Standard Time': 'Australia/Darwin',
'Nepal Standard Time': 'Asia/Katmandu',
'New Zealand Standard Time': 'Pacific/Auckland',
'Newfoundland Standard Time': 'America/St_Johns',
'Norfolk Standard Time': 'Pacific/Norfolk',
'North Asia East Standard Time': 'Asia/Irkutsk',
'North Asia Standard Time': 'Asia/Krasnoyarsk',
'North Korea Standard Time': 'Asia/Pyongyang',
'Omsk Standard Time': 'Asia/Omsk',
'Pacific SA Standard Time': 'America/Santiago',
'Pacific Standard Time': 'America/Los_Angeles',
'Pacific Standard Time (Mexico)': 'America/Tijuana',
'Pakistan Standard Time': 'Asia/Karachi',
'Paraguay Standard Time': 'America/Asuncion',
'Romance Standard Time': 'Europe/Paris',
@ -81,6 +95,8 @@ win_tz = {'AUS Central Standard Time': 'Australia/Darwin',
'SA Pacific Standard Time': 'America/Bogota',
'SA Western Standard Time': 'America/La_Paz',
'SE Asia Standard Time': 'Asia/Bangkok',
'Saint Pierre Standard Time': 'America/Miquelon',
'Sakhalin Standard Time': 'Asia/Sakhalin',
'Samoa Standard Time': 'Pacific/Apia',
'Singapore Standard Time': 'Asia/Singapore',
'South Africa Standard Time': 'Africa/Johannesburg',
@ -88,14 +104,20 @@ win_tz = {'AUS Central Standard Time': 'Australia/Darwin',
'Syria Standard Time': 'Asia/Damascus',
'Taipei Standard Time': 'Asia/Taipei',
'Tasmania Standard Time': 'Australia/Hobart',
'Tocantins Standard Time': 'America/Araguaina',
'Tokyo Standard Time': 'Asia/Tokyo',
'Tomsk Standard Time': 'Asia/Tomsk',
'Tonga Standard Time': 'Pacific/Tongatapu',
'Transbaikal Standard Time': 'Asia/Chita',
'Turkey Standard Time': 'Europe/Istanbul',
'Turks And Caicos Standard Time': 'America/Grand_Turk',
'US Eastern Standard Time': 'America/Indianapolis',
'US Mountain Standard Time': 'America/Phoenix',
'UTC': 'Etc/GMT',
'UTC+12': 'Etc/GMT-12',
'UTC-02': 'Etc/GMT+2',
'UTC-08': 'Etc/GMT+8',
'UTC-09': 'Etc/GMT+9',
'UTC-11': 'Etc/GMT+11',
'Ulaanbaatar Standard Time': 'Asia/Ulaanbaatar',
'Venezuela Standard Time': 'America/Caracas',
@ -103,7 +125,9 @@ win_tz = {'AUS Central Standard Time': 'Australia/Darwin',
'W. Australia Standard Time': 'Australia/Perth',
'W. Central Africa Standard Time': 'Africa/Lagos',
'W. Europe Standard Time': 'Europe/Berlin',
'W. Mongolia Standard Time': 'Asia/Hovd',
'West Asia Standard Time': 'Asia/Tashkent',
'West Bank Standard Time': 'Asia/Hebron',
'West Pacific Standard Time': 'Pacific/Port_Moresby',
'Yakutsk Standard Time': 'Asia/Yakutsk'}
@ -162,10 +186,11 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Africa/Tripoli': 'Libya Standard Time',
'Africa/Tunis': 'W. Central Africa Standard Time',
'Africa/Windhoek': 'Namibia Standard Time',
'America/Adak': 'Aleutian Standard Time',
'America/Anchorage': 'Alaskan Standard Time',
'America/Anguilla': 'SA Western Standard Time',
'America/Antigua': 'SA Western Standard Time',
'America/Araguaina': 'SA Eastern Standard Time',
'America/Araguaina': 'Tocantins Standard Time',
'America/Argentina/La_Rioja': 'Argentina Standard Time',
'America/Argentina/Rio_Gallegos': 'Argentina Standard Time',
'America/Argentina/Salta': 'Argentina Standard Time',
@ -214,14 +239,14 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'America/Glace_Bay': 'Atlantic Standard Time',
'America/Godthab': 'Greenland Standard Time',
'America/Goose_Bay': 'Atlantic Standard Time',
'America/Grand_Turk': 'SA Western Standard Time',
'America/Grand_Turk': 'Turks And Caicos Standard Time',
'America/Grenada': 'SA Western Standard Time',
'America/Guadeloupe': 'SA Western Standard Time',
'America/Guatemala': 'Central America Standard Time',
'America/Guayaquil': 'SA Pacific Standard Time',
'America/Guyana': 'SA Western Standard Time',
'America/Halifax': 'Atlantic Standard Time',
'America/Havana': 'Eastern Standard Time',
'America/Havana': 'Cuba Standard Time',
'America/Hermosillo': 'US Mountain Standard Time',
'America/Indiana/Knox': 'Central Standard Time',
'America/Indiana/Marengo': 'US Eastern Standard Time',
@ -255,6 +280,7 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'America/Merida': 'Central Standard Time (Mexico)',
'America/Metlakatla': 'Alaskan Standard Time',
'America/Mexico_City': 'Central Standard Time (Mexico)',
'America/Miquelon': 'Saint Pierre Standard Time',
'America/Moncton': 'Atlantic Standard Time',
'America/Monterrey': 'Central Standard Time (Mexico)',
'America/Montevideo': 'Montevideo Standard Time',
@ -273,17 +299,18 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'America/Pangnirtung': 'Eastern Standard Time',
'America/Paramaribo': 'SA Eastern Standard Time',
'America/Phoenix': 'US Mountain Standard Time',
'America/Port-au-Prince': 'Eastern Standard Time',
'America/Port-au-Prince': 'Haiti Standard Time',
'America/Port_of_Spain': 'SA Western Standard Time',
'America/Porto_Velho': 'SA Western Standard Time',
'America/Puerto_Rico': 'SA Western Standard Time',
'America/Punta_Arenas': 'SA Eastern Standard Time',
'America/Rainy_River': 'Central Standard Time',
'America/Rankin_Inlet': 'Central Standard Time',
'America/Recife': 'SA Eastern Standard Time',
'America/Regina': 'Canada Central Standard Time',
'America/Resolute': 'Central Standard Time',
'America/Rio_Branco': 'SA Pacific Standard Time',
'America/Santa_Isabel': 'Pacific Standard Time',
'America/Santa_Isabel': 'Pacific Standard Time (Mexico)',
'America/Santarem': 'SA Eastern Standard Time',
'America/Santiago': 'Pacific SA Standard Time',
'America/Santo_Domingo': 'SA Western Standard Time',
@ -300,7 +327,7 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'America/Tegucigalpa': 'Central America Standard Time',
'America/Thule': 'Atlantic Standard Time',
'America/Thunder_Bay': 'Eastern Standard Time',
'America/Tijuana': 'Pacific Standard Time',
'America/Tijuana': 'Pacific Standard Time (Mexico)',
'America/Toronto': 'Eastern Standard Time',
'America/Tortola': 'SA Western Standard Time',
'America/Vancouver': 'Pacific Standard Time',
@ -308,13 +335,13 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'America/Winnipeg': 'Central Standard Time',
'America/Yakutat': 'Alaskan Standard Time',
'America/Yellowknife': 'Mountain Standard Time',
'Antarctica/Casey': 'W. Australia Standard Time',
'Antarctica/Casey': 'Central Pacific Standard Time',
'Antarctica/Davis': 'SE Asia Standard Time',
'Antarctica/DumontDUrville': 'West Pacific Standard Time',
'Antarctica/Macquarie': 'Central Pacific Standard Time',
'Antarctica/Mawson': 'West Asia Standard Time',
'Antarctica/McMurdo': 'New Zealand Standard Time',
'Antarctica/Palmer': 'Pacific SA Standard Time',
'Antarctica/Palmer': 'SA Eastern Standard Time',
'Antarctica/Rothera': 'SA Eastern Standard Time',
'Antarctica/Syowa': 'E. Africa Standard Time',
'Antarctica/Vostok': 'Central Asia Standard Time',
@ -326,15 +353,17 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Asia/Aqtau': 'West Asia Standard Time',
'Asia/Aqtobe': 'West Asia Standard Time',
'Asia/Ashgabat': 'West Asia Standard Time',
'Asia/Atyrau': 'West Asia Standard Time',
'Asia/Baghdad': 'Arabic Standard Time',
'Asia/Bahrain': 'Arab Standard Time',
'Asia/Baku': 'Azerbaijan Standard Time',
'Asia/Bangkok': 'SE Asia Standard Time',
'Asia/Barnaul': 'Altai Standard Time',
'Asia/Beirut': 'Middle East Standard Time',
'Asia/Bishkek': 'Central Asia Standard Time',
'Asia/Brunei': 'Singapore Standard Time',
'Asia/Calcutta': 'India Standard Time',
'Asia/Chita': 'Yakutsk Standard Time',
'Asia/Chita': 'Transbaikal Standard Time',
'Asia/Choibalsan': 'Ulaanbaatar Standard Time',
'Asia/Colombo': 'Sri Lanka Standard Time',
'Asia/Damascus': 'Syria Standard Time',
@ -342,7 +371,11 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Asia/Dili': 'Tokyo Standard Time',
'Asia/Dubai': 'Arabian Standard Time',
'Asia/Dushanbe': 'West Asia Standard Time',
'Asia/Famagusta': 'Turkey Standard Time',
'Asia/Gaza': 'West Bank Standard Time',
'Asia/Hebron': 'West Bank Standard Time',
'Asia/Hong_Kong': 'China Standard Time',
'Asia/Hovd': 'W. Mongolia Standard Time',
'Asia/Irkutsk': 'North Asia East Standard Time',
'Asia/Jakarta': 'SE Asia Standard Time',
'Asia/Jayapura': 'Tokyo Standard Time',
@ -364,7 +397,7 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Asia/Nicosia': 'GTB Standard Time',
'Asia/Novokuznetsk': 'North Asia Standard Time',
'Asia/Novosibirsk': 'N. Central Asia Standard Time',
'Asia/Omsk': 'N. Central Asia Standard Time',
'Asia/Omsk': 'Omsk Standard Time',
'Asia/Oral': 'West Asia Standard Time',
'Asia/Phnom_Penh': 'SE Asia Standard Time',
'Asia/Pontianak': 'SE Asia Standard Time',
@ -374,7 +407,7 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Asia/Rangoon': 'Myanmar Standard Time',
'Asia/Riyadh': 'Arab Standard Time',
'Asia/Saigon': 'SE Asia Standard Time',
'Asia/Sakhalin': 'Vladivostok Standard Time',
'Asia/Sakhalin': 'Sakhalin Standard Time',
'Asia/Samarkand': 'West Asia Standard Time',
'Asia/Seoul': 'Korea Standard Time',
'Asia/Shanghai': 'China Standard Time',
@ -386,6 +419,7 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Asia/Tehran': 'Iran Standard Time',
'Asia/Thimphu': 'Bangladesh Standard Time',
'Asia/Tokyo': 'Tokyo Standard Time',
'Asia/Tomsk': 'Tomsk Standard Time',
'Asia/Ulaanbaatar': 'Ulaanbaatar Standard Time',
'Asia/Urumqi': 'Central Asia Standard Time',
'Asia/Ust-Nera': 'Vladivostok Standard Time',
@ -409,8 +443,10 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Australia/Broken_Hill': 'Cen. Australia Standard Time',
'Australia/Currie': 'Tasmania Standard Time',
'Australia/Darwin': 'AUS Central Standard Time',
'Australia/Eucla': 'Aus Central W. Standard Time',
'Australia/Hobart': 'Tasmania Standard Time',
'Australia/Lindeman': 'E. Australia Standard Time',
'Australia/Lord_Howe': 'Lord Howe Standard Time',
'Australia/Melbourne': 'AUS Eastern Standard Time',
'Australia/Perth': 'W. Australia Standard Time',
'Australia/Sydney': 'AUS Eastern Standard Time',
@ -427,6 +463,8 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Etc/GMT+5': 'SA Pacific Standard Time',
'Etc/GMT+6': 'Central America Standard Time',
'Etc/GMT+7': 'US Mountain Standard Time',
'Etc/GMT+8': 'UTC-08',
'Etc/GMT+9': 'UTC-09',
'Etc/GMT-1': 'W. Central Africa Standard Time',
'Etc/GMT-10': 'West Pacific Standard Time',
'Etc/GMT-11': 'Central Pacific Standard Time',
@ -444,6 +482,7 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Etc/UTC': 'UTC',
'Europe/Amsterdam': 'W. Europe Standard Time',
'Europe/Andorra': 'W. Europe Standard Time',
'Europe/Astrakhan': 'Astrakhan Standard Time',
'Europe/Athens': 'GTB Standard Time',
'Europe/Belgrade': 'Central Europe Standard Time',
'Europe/Berlin': 'W. Europe Standard Time',
@ -463,6 +502,7 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Europe/Jersey': 'GMT Standard Time',
'Europe/Kaliningrad': 'Kaliningrad Standard Time',
'Europe/Kiev': 'FLE Standard Time',
'Europe/Kirov': 'Russian Standard Time',
'Europe/Lisbon': 'GMT Standard Time',
'Europe/Ljubljana': 'Central Europe Standard Time',
'Europe/London': 'GMT Standard Time',
@ -482,12 +522,14 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Europe/Samara': 'Russia Time Zone 3',
'Europe/San_Marino': 'W. Europe Standard Time',
'Europe/Sarajevo': 'Central European Standard Time',
'Europe/Saratov': 'Astrakhan Standard Time',
'Europe/Simferopol': 'Russian Standard Time',
'Europe/Skopje': 'Central European Standard Time',
'Europe/Sofia': 'FLE Standard Time',
'Europe/Stockholm': 'W. Europe Standard Time',
'Europe/Tallinn': 'FLE Standard Time',
'Europe/Tirane': 'Central Europe Standard Time',
'Europe/Ulyanovsk': 'Astrakhan Standard Time',
'Europe/Uzhgorod': 'FLE Standard Time',
'Europe/Vaduz': 'W. Europe Standard Time',
'Europe/Vatican': 'W. Europe Standard Time',
@ -513,14 +555,16 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'PST8PDT': 'Pacific Standard Time',
'Pacific/Apia': 'Samoa Standard Time',
'Pacific/Auckland': 'New Zealand Standard Time',
'Pacific/Bougainville': 'Central Pacific Standard Time',
'Pacific/Easter': 'SA Pacific Standard Time',
'Pacific/Bougainville': 'Bougainville Standard Time',
'Pacific/Chatham': 'Chatham Islands Standard Time',
'Pacific/Easter': 'Easter Island Standard Time',
'Pacific/Efate': 'Central Pacific Standard Time',
'Pacific/Enderbury': 'Tonga Standard Time',
'Pacific/Fakaofo': 'Tonga Standard Time',
'Pacific/Fiji': 'Fiji Standard Time',
'Pacific/Funafuti': 'UTC+12',
'Pacific/Galapagos': 'Central America Standard Time',
'Pacific/Gambier': 'UTC-09',
'Pacific/Guadalcanal': 'Central Pacific Standard Time',
'Pacific/Guam': 'West Pacific Standard Time',
'Pacific/Honolulu': 'Hawaiian Standard Time',
@ -529,13 +573,15 @@ tz_win = {'Africa/Abidjan': 'Greenwich Standard Time',
'Pacific/Kosrae': 'Central Pacific Standard Time',
'Pacific/Kwajalein': 'UTC+12',
'Pacific/Majuro': 'UTC+12',
'Pacific/Marquesas': 'Marquesas Standard Time',
'Pacific/Midway': 'UTC-11',
'Pacific/Nauru': 'UTC+12',
'Pacific/Niue': 'UTC-11',
'Pacific/Norfolk': 'Central Pacific Standard Time',
'Pacific/Norfolk': 'Norfolk Standard Time',
'Pacific/Noumea': 'Central Pacific Standard Time',
'Pacific/Pago_Pago': 'UTC-11',
'Pacific/Palau': 'Tokyo Standard Time',
'Pacific/Pitcairn': 'UTC-08',
'Pacific/Ponape': 'Central Pacific Standard Time',
'Pacific/Port_Moresby': 'West Pacific Standard Time',
'Pacific/Rarotonga': 'Hawaiian Standard Time',