tzlocal-1.2/0000775000175000017500000000000012537263230014455 5ustar lregebrolregebro00000000000000tzlocal-1.2/README.rst0000664000175000017500000000403112537263222016143 0ustar lregebrolregebro00000000000000tzlocal ======= This Python module returns a `tzinfo` object with the local timezone information under Unix and Win-32. It requires `pytz`, and returns `pytz` `tzinfo` objects. This module attempts to fix a glaring hole in `pytz`, that there is no way to get the local timezone information, unless you know the zoneinfo name, and under several Linux distros that's hard or impossible to figure out. Also, with Windows different timezone system using pytz isn't of much use unless you separately configure the zoneinfo timezone name. With `tzlocal` you only need to call `get_localzone()` and you will get a `tzinfo` object with the local time zone info. On some Unices you will still not get to know what the timezone name is, but you don't need that when you have the tzinfo file. However, if the timezone name is readily available it will be used. Supported systems ----------------- These are the systems that are in theory supported: * Windows 2000 and later * Any unix-like system with a /etc/localtime or /usr/local/etc/localtime If you have one of the above systems and it does not work, it's a bug. Please report it. Usage ----- Load the local timezone: >>> from tzlocal import get_localzone >>> tz = get_localzone() >>> tz Create a local datetime: >>> from datetime import datetime >>> dt = tz.localize(datetime(2015, 4, 10, 7, 22)) >>> dt datetime.datetime(2015, 4, 10, 7, 22, tzinfo=) Lookup another timezone with `pytz`: >>> import pytz >>> eastern = pytz.timezone('US/Eastern') Convert the datetime: >>> dt.astimezone(eastern) datetime.datetime(2015, 4, 10, 1, 2, tzinfo=) Maintainer ---------- * Lennart Regebro, regebro@gmail.com Contributors ------------ * Marc Van Olmen * Benjamen Meyer * Manuel Ebert * Xiaokun Zhu * Cameris (Sorry if I forgot someone) License ------- * CC0 1.0 Universal http://creativecommons.org/publicdomain/zero/1.0/ tzlocal-1.2/tzlocal.egg-info/0000775000175000017500000000000012537263230017617 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal.egg-info/zip-safe0000664000175000017500000000000112537263222021250 0ustar lregebrolregebro00000000000000 tzlocal-1.2/tzlocal.egg-info/PKG-INFO0000664000175000017500000001302612537263224020721 0ustar lregebrolregebro00000000000000Metadata-Version: 1.1 Name: tzlocal Version: 1.2 Summary: tzinfo object for the local timezone Home-page: https://github.com/regebro/tzlocal Author: Lennart Regebro Author-email: regebro@gmail.com License: CC0 1.0 Universal Description: tzlocal ======= This Python module returns a `tzinfo` object with the local timezone information under Unix and Win-32. It requires `pytz`, and returns `pytz` `tzinfo` objects. This module attempts to fix a glaring hole in `pytz`, that there is no way to get the local timezone information, unless you know the zoneinfo name, and under several Linux distros that's hard or impossible to figure out. Also, with Windows different timezone system using pytz isn't of much use unless you separately configure the zoneinfo timezone name. With `tzlocal` you only need to call `get_localzone()` and you will get a `tzinfo` object with the local time zone info. On some Unices you will still not get to know what the timezone name is, but you don't need that when you have the tzinfo file. However, if the timezone name is readily available it will be used. Supported systems ----------------- These are the systems that are in theory supported: * Windows 2000 and later * Any unix-like system with a /etc/localtime or /usr/local/etc/localtime If you have one of the above systems and it does not work, it's a bug. Please report it. Usage ----- Load the local timezone: >>> from tzlocal import get_localzone >>> tz = get_localzone() >>> tz Create a local datetime: >>> from datetime import datetime >>> dt = tz.localize(datetime(2015, 4, 10, 7, 22)) >>> dt datetime.datetime(2015, 4, 10, 7, 22, tzinfo=) Lookup another timezone with `pytz`: >>> import pytz >>> eastern = pytz.timezone('US/Eastern') Convert the datetime: >>> dt.astimezone(eastern) datetime.datetime(2015, 4, 10, 1, 2, tzinfo=) Maintainer ---------- * Lennart Regebro, regebro@gmail.com Contributors ------------ * Marc Van Olmen * Benjamen Meyer * Manuel Ebert * Xiaokun Zhu * Cameris (Sorry if I forgot someone) License ------- * CC0 1.0 Universal http://creativecommons.org/publicdomain/zero/1.0/ Changes ======= 1.2 (2015-06-14) ---------------- - Systemd stores no time zone name, forcing us to look at the name of the file that localtime symlinks to. (cameris) 1.1.2 (2014-10-18) ------------------ - Timezones that has 3 items did not work on Mac OS X. (Marc Van Olmen) - Now doesn't fail if the TZ environment variable isn't an Olsen time zone. - Some timezones on Windows can apparently be empty (perhaps the are deleted). Now these are ignored. (Xiaokun Zhu) 1.1.1 (2014-01-29) ------------------ - I forgot to add Etc/UTC as an alias for Etc/GMT. 1.1 (2014-01-28) ---------------- - Adding better support for OS X. - Added support to map from tzdata/Olsen names to Windows names. (Thanks to Benjamen Meyer). 1.0 (2013-05-29) ---------------- - Fixed some more cases where spaces needs replacing with underscores. - Better handling of misconfigured /etc/timezone. - Better error message on Windows if we can't find a timezone at all. 0.3 (2012-09-13) ---------------- - Windows 7 support. - Python 2.5 supported; because it only needed a __future__ import. - Python 3.3 tested, it worked. - Got rid of relative imports, because I don't actually like them, so I don't know why I used them in the first place. - For each Windows zone, use the default zoneinfo zone, not the last one. 0.2 (2012-09-12) ---------------- - Python 3 support. 0.1 (2012-09-11) ---------------- - Initial release. Keywords: timezone pytz Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication Classifier: Operating System :: Microsoft :: Windows Classifier: Operating System :: Unix Classifier: Operating System :: MacOS :: MacOS X Classifier: Programming Language :: Python :: 2.5 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.1 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 tzlocal-1.2/tzlocal.egg-info/SOURCES.txt0000664000175000017500000000133212537263224021505 0ustar lregebrolregebro00000000000000CHANGES.txt LICENSE.txt MANIFEST.in README.rst get_windows_info.py setup.cfg setup.py tzlocal/__init__.py tzlocal/darwin.py tzlocal/tests.py tzlocal/unix.py tzlocal/win32.py tzlocal/windows_tz.py tzlocal.egg-info/PKG-INFO tzlocal.egg-info/SOURCES.txt tzlocal.egg-info/dependency_links.txt tzlocal.egg-info/pbr.json tzlocal.egg-info/requires.txt tzlocal.egg-info/top_level.txt tzlocal.egg-info/zip-safe tzlocal/test_data/Harare tzlocal/test_data/localtime/etc/localtime tzlocal/test_data/symlink_localtime/etc/localtime tzlocal/test_data/symlink_localtime/usr/share/zoneinfo/Africa/Harare tzlocal/test_data/timezone/etc/timezone tzlocal/test_data/timezone_setting/etc/conf.d/clock tzlocal/test_data/zone_setting/etc/sysconfig/clocktzlocal-1.2/tzlocal.egg-info/top_level.txt0000664000175000017500000000001012537263224022343 0ustar lregebrolregebro00000000000000tzlocal tzlocal-1.2/tzlocal.egg-info/dependency_links.txt0000664000175000017500000000000112537263224023670 0ustar lregebrolregebro00000000000000 tzlocal-1.2/tzlocal.egg-info/pbr.json0000664000175000017500000000005612537263224021301 0ustar lregebrolregebro00000000000000{"is_release": true, "git_version": "440ede1"}tzlocal-1.2/tzlocal.egg-info/requires.txt0000664000175000017500000000000412537263224022214 0ustar lregebrolregebro00000000000000pytztzlocal-1.2/CHANGES.txt0000664000175000017500000000264312537263222016274 0ustar lregebrolregebro00000000000000Changes ======= 1.2 (2015-06-14) ---------------- - Systemd stores no time zone name, forcing us to look at the name of the file that localtime symlinks to. (cameris) 1.1.2 (2014-10-18) ------------------ - Timezones that has 3 items did not work on Mac OS X. (Marc Van Olmen) - Now doesn't fail if the TZ environment variable isn't an Olsen time zone. - Some timezones on Windows can apparently be empty (perhaps the are deleted). Now these are ignored. (Xiaokun Zhu) 1.1.1 (2014-01-29) ------------------ - I forgot to add Etc/UTC as an alias for Etc/GMT. 1.1 (2014-01-28) ---------------- - Adding better support for OS X. - Added support to map from tzdata/Olsen names to Windows names. (Thanks to Benjamen Meyer). 1.0 (2013-05-29) ---------------- - Fixed some more cases where spaces needs replacing with underscores. - Better handling of misconfigured /etc/timezone. - Better error message on Windows if we can't find a timezone at all. 0.3 (2012-09-13) ---------------- - Windows 7 support. - Python 2.5 supported; because it only needed a __future__ import. - Python 3.3 tested, it worked. - Got rid of relative imports, because I don't actually like them, so I don't know why I used them in the first place. - For each Windows zone, use the default zoneinfo zone, not the last one. 0.2 (2012-09-12) ---------------- - Python 3 support. 0.1 (2012-09-11) ---------------- - Initial release. tzlocal-1.2/PKG-INFO0000664000175000017500000001302612537263230015554 0ustar lregebrolregebro00000000000000Metadata-Version: 1.1 Name: tzlocal Version: 1.2 Summary: tzinfo object for the local timezone Home-page: https://github.com/regebro/tzlocal Author: Lennart Regebro Author-email: regebro@gmail.com License: CC0 1.0 Universal Description: tzlocal ======= This Python module returns a `tzinfo` object with the local timezone information under Unix and Win-32. It requires `pytz`, and returns `pytz` `tzinfo` objects. This module attempts to fix a glaring hole in `pytz`, that there is no way to get the local timezone information, unless you know the zoneinfo name, and under several Linux distros that's hard or impossible to figure out. Also, with Windows different timezone system using pytz isn't of much use unless you separately configure the zoneinfo timezone name. With `tzlocal` you only need to call `get_localzone()` and you will get a `tzinfo` object with the local time zone info. On some Unices you will still not get to know what the timezone name is, but you don't need that when you have the tzinfo file. However, if the timezone name is readily available it will be used. Supported systems ----------------- These are the systems that are in theory supported: * Windows 2000 and later * Any unix-like system with a /etc/localtime or /usr/local/etc/localtime If you have one of the above systems and it does not work, it's a bug. Please report it. Usage ----- Load the local timezone: >>> from tzlocal import get_localzone >>> tz = get_localzone() >>> tz Create a local datetime: >>> from datetime import datetime >>> dt = tz.localize(datetime(2015, 4, 10, 7, 22)) >>> dt datetime.datetime(2015, 4, 10, 7, 22, tzinfo=) Lookup another timezone with `pytz`: >>> import pytz >>> eastern = pytz.timezone('US/Eastern') Convert the datetime: >>> dt.astimezone(eastern) datetime.datetime(2015, 4, 10, 1, 2, tzinfo=) Maintainer ---------- * Lennart Regebro, regebro@gmail.com Contributors ------------ * Marc Van Olmen * Benjamen Meyer * Manuel Ebert * Xiaokun Zhu * Cameris (Sorry if I forgot someone) License ------- * CC0 1.0 Universal http://creativecommons.org/publicdomain/zero/1.0/ Changes ======= 1.2 (2015-06-14) ---------------- - Systemd stores no time zone name, forcing us to look at the name of the file that localtime symlinks to. (cameris) 1.1.2 (2014-10-18) ------------------ - Timezones that has 3 items did not work on Mac OS X. (Marc Van Olmen) - Now doesn't fail if the TZ environment variable isn't an Olsen time zone. - Some timezones on Windows can apparently be empty (perhaps the are deleted). Now these are ignored. (Xiaokun Zhu) 1.1.1 (2014-01-29) ------------------ - I forgot to add Etc/UTC as an alias for Etc/GMT. 1.1 (2014-01-28) ---------------- - Adding better support for OS X. - Added support to map from tzdata/Olsen names to Windows names. (Thanks to Benjamen Meyer). 1.0 (2013-05-29) ---------------- - Fixed some more cases where spaces needs replacing with underscores. - Better handling of misconfigured /etc/timezone. - Better error message on Windows if we can't find a timezone at all. 0.3 (2012-09-13) ---------------- - Windows 7 support. - Python 2.5 supported; because it only needed a __future__ import. - Python 3.3 tested, it worked. - Got rid of relative imports, because I don't actually like them, so I don't know why I used them in the first place. - For each Windows zone, use the default zoneinfo zone, not the last one. 0.2 (2012-09-12) ---------------- - Python 3 support. 0.1 (2012-09-11) ---------------- - Initial release. Keywords: timezone pytz Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication Classifier: Operating System :: Microsoft :: Windows Classifier: Operating System :: Unix Classifier: Operating System :: MacOS :: MacOS X Classifier: Programming Language :: Python :: 2.5 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.1 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 tzlocal-1.2/tzlocal/0000775000175000017500000000000012537263230016125 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/darwin.py0000664000175000017500000000151212537263222017763 0ustar lregebrolregebro00000000000000from __future__ import with_statement import os import pytz _cache_tz = None def _get_localzone(): tzname = os.popen("systemsetup -gettimezone").read().replace("Time Zone: ", "").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") tzname = link[link.rfind("zoneinfo/") + 9:] return pytz.timezone(tzname) def get_localzone(): """Get the computers configured local timezone, if any.""" global _cache_tz if _cache_tz is None: _cache_tz = _get_localzone() return _cache_tz def reload_localzone(): """Reload the cached localzone. You need to call this if the timezone has changed.""" global _cache_tz _cache_tz = _get_localzone() return _cache_tz tzlocal-1.2/tzlocal/windows_tz.py0000664000175000017500000006063312537263222020717 0ustar lregebrolregebro00000000000000# This file is autogenerated by the get_windows_info.py script # Do not edit. win_tz = {'AUS Central Standard Time': 'Australia/Darwin', 'AUS Eastern Standard Time': 'Australia/Sydney', 'Afghanistan Standard Time': 'Asia/Kabul', 'Alaskan Standard Time': 'America/Anchorage', 'Arab Standard Time': 'Asia/Riyadh', 'Arabian Standard Time': 'Asia/Dubai', 'Arabic Standard Time': 'Asia/Baghdad', 'Argentina Standard Time': 'America/Buenos_Aires', 'Atlantic Standard Time': 'America/Halifax', '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', 'Canada Central Standard Time': 'America/Regina', 'Cape Verde Standard Time': 'Atlantic/Cape_Verde', 'Caucasus Standard Time': 'Asia/Yerevan', 'Cen. Australia Standard Time': 'Australia/Adelaide', 'Central America Standard Time': 'America/Guatemala', 'Central Asia Standard Time': 'Asia/Almaty', 'Central Brazilian Standard Time': 'America/Cuiaba', 'Central Europe Standard Time': 'Europe/Budapest', 'Central European Standard Time': 'Europe/Warsaw', 'Central Pacific Standard Time': 'Pacific/Guadalcanal', 'Central Standard Time': 'America/Chicago', 'Central Standard Time (Mexico)': 'America/Mexico_City', 'China Standard Time': 'Asia/Shanghai', 'Dateline Standard Time': 'Etc/GMT+12', 'E. Africa Standard Time': 'Africa/Nairobi', 'E. Australia Standard Time': 'Australia/Brisbane', 'E. South America Standard Time': 'America/Sao_Paulo', 'Eastern Standard Time': 'America/New_York', 'Egypt Standard Time': 'Africa/Cairo', 'Ekaterinburg Standard Time': 'Asia/Yekaterinburg', 'FLE Standard Time': 'Europe/Kiev', 'Fiji Standard Time': 'Pacific/Fiji', 'GMT Standard Time': 'Europe/London', 'GTB Standard Time': 'Europe/Bucharest', 'Georgian Standard Time': 'Asia/Tbilisi', 'Greenland Standard Time': 'America/Godthab', 'Greenwich Standard Time': 'Atlantic/Reykjavik', 'Hawaiian Standard Time': 'Pacific/Honolulu', 'India Standard Time': 'Asia/Calcutta', 'Iran Standard Time': 'Asia/Tehran', 'Israel Standard Time': 'Asia/Jerusalem', 'Jordan Standard Time': 'Asia/Amman', 'Kaliningrad Standard Time': 'Europe/Kaliningrad', 'Korea Standard Time': 'Asia/Seoul', 'Libya Standard Time': 'Africa/Tripoli', 'Line Islands Standard Time': 'Pacific/Kiritimati', 'Magadan Standard Time': 'Asia/Magadan', 'Mauritius Standard Time': 'Indian/Mauritius', 'Middle East Standard Time': 'Asia/Beirut', 'Montevideo Standard Time': 'America/Montevideo', 'Morocco Standard Time': 'Africa/Casablanca', 'Mountain Standard Time': 'America/Denver', 'Mountain Standard Time (Mexico)': 'America/Chihuahua', 'Myanmar Standard Time': 'Asia/Rangoon', 'N. Central Asia Standard Time': 'Asia/Novosibirsk', 'Namibia Standard Time': 'Africa/Windhoek', 'Nepal Standard Time': 'Asia/Katmandu', 'New Zealand Standard Time': 'Pacific/Auckland', 'Newfoundland Standard Time': 'America/St_Johns', 'North Asia East Standard Time': 'Asia/Irkutsk', 'North Asia Standard Time': 'Asia/Krasnoyarsk', 'Pacific SA Standard Time': 'America/Santiago', 'Pacific Standard Time': 'America/Los_Angeles', 'Pacific Standard Time (Mexico)': 'America/Santa_Isabel', 'Pakistan Standard Time': 'Asia/Karachi', 'Paraguay Standard Time': 'America/Asuncion', 'Romance Standard Time': 'Europe/Paris', 'Russia Time Zone 10': 'Asia/Srednekolymsk', 'Russia Time Zone 11': 'Asia/Kamchatka', 'Russia Time Zone 3': 'Europe/Samara', 'Russian Standard Time': 'Europe/Moscow', 'SA Eastern Standard Time': 'America/Cayenne', 'SA Pacific Standard Time': 'America/Bogota', 'SA Western Standard Time': 'America/La_Paz', 'SE Asia Standard Time': 'Asia/Bangkok', 'Samoa Standard Time': 'Pacific/Apia', 'Singapore Standard Time': 'Asia/Singapore', 'South Africa Standard Time': 'Africa/Johannesburg', 'Sri Lanka Standard Time': 'Asia/Colombo', 'Syria Standard Time': 'Asia/Damascus', 'Taipei Standard Time': 'Asia/Taipei', 'Tasmania Standard Time': 'Australia/Hobart', 'Tokyo Standard Time': 'Asia/Tokyo', 'Tonga Standard Time': 'Pacific/Tongatapu', 'Turkey Standard Time': 'Europe/Istanbul', '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-11': 'Etc/GMT+11', 'Ulaanbaatar Standard Time': 'Asia/Ulaanbaatar', 'Venezuela Standard Time': 'America/Caracas', 'Vladivostok Standard Time': 'Asia/Vladivostok', 'W. Australia Standard Time': 'Australia/Perth', 'W. Central Africa Standard Time': 'Africa/Lagos', 'W. Europe Standard Time': 'Europe/Berlin', 'West Asia Standard Time': 'Asia/Tashkent', 'West Pacific Standard Time': 'Pacific/Port_Moresby', 'Yakutsk Standard Time': 'Asia/Yakutsk'} # Old name for the win_tz variable: tz_names = win_tz tz_win = {'Africa/Abidjan': 'Greenwich Standard Time', 'Africa/Accra': 'Greenwich Standard Time', 'Africa/Addis_Ababa': 'E. Africa Standard Time', 'Africa/Algiers': 'W. Central Africa Standard Time', 'Africa/Asmera': 'E. Africa Standard Time', 'Africa/Bamako': 'Greenwich Standard Time', 'Africa/Bangui': 'W. Central Africa Standard Time', 'Africa/Banjul': 'Greenwich Standard Time', 'Africa/Bissau': 'Greenwich Standard Time', 'Africa/Blantyre': 'South Africa Standard Time', 'Africa/Brazzaville': 'W. Central Africa Standard Time', 'Africa/Bujumbura': 'South Africa Standard Time', 'Africa/Cairo': 'Egypt Standard Time', 'Africa/Casablanca': 'Morocco Standard Time', 'Africa/Ceuta': 'Romance Standard Time', 'Africa/Conakry': 'Greenwich Standard Time', 'Africa/Dakar': 'Greenwich Standard Time', 'Africa/Dar_es_Salaam': 'E. Africa Standard Time', 'Africa/Djibouti': 'E. Africa Standard Time', 'Africa/Douala': 'W. Central Africa Standard Time', 'Africa/El_Aaiun': 'Morocco Standard Time', 'Africa/Freetown': 'Greenwich Standard Time', 'Africa/Gaborone': 'South Africa Standard Time', 'Africa/Harare': 'South Africa Standard Time', 'Africa/Johannesburg': 'South Africa Standard Time', 'Africa/Juba': 'E. Africa Standard Time', 'Africa/Kampala': 'E. Africa Standard Time', 'Africa/Khartoum': 'E. Africa Standard Time', 'Africa/Kigali': 'South Africa Standard Time', 'Africa/Kinshasa': 'W. Central Africa Standard Time', 'Africa/Lagos': 'W. Central Africa Standard Time', 'Africa/Libreville': 'W. Central Africa Standard Time', 'Africa/Lome': 'Greenwich Standard Time', 'Africa/Luanda': 'W. Central Africa Standard Time', 'Africa/Lubumbashi': 'South Africa Standard Time', 'Africa/Lusaka': 'South Africa Standard Time', 'Africa/Malabo': 'W. Central Africa Standard Time', 'Africa/Maputo': 'South Africa Standard Time', 'Africa/Maseru': 'South Africa Standard Time', 'Africa/Mbabane': 'South Africa Standard Time', 'Africa/Mogadishu': 'E. Africa Standard Time', 'Africa/Monrovia': 'Greenwich Standard Time', 'Africa/Nairobi': 'E. Africa Standard Time', 'Africa/Ndjamena': 'W. Central Africa Standard Time', 'Africa/Niamey': 'W. Central Africa Standard Time', 'Africa/Nouakchott': 'Greenwich Standard Time', 'Africa/Ouagadougou': 'Greenwich Standard Time', 'Africa/Porto-Novo': 'W. Central Africa Standard Time', 'Africa/Sao_Tome': 'Greenwich Standard Time', 'Africa/Tripoli': 'Libya Standard Time', 'Africa/Tunis': 'W. Central Africa Standard Time', 'Africa/Windhoek': 'Namibia 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/Argentina/La_Rioja': 'Argentina Standard Time', 'America/Argentina/Rio_Gallegos': 'Argentina Standard Time', 'America/Argentina/Salta': 'Argentina Standard Time', 'America/Argentina/San_Juan': 'Argentina Standard Time', 'America/Argentina/San_Luis': 'Argentina Standard Time', 'America/Argentina/Tucuman': 'Argentina Standard Time', 'America/Argentina/Ushuaia': 'Argentina Standard Time', 'America/Aruba': 'SA Western Standard Time', 'America/Asuncion': 'Paraguay Standard Time', 'America/Bahia': 'Bahia Standard Time', 'America/Bahia_Banderas': 'Central Standard Time (Mexico)', 'America/Barbados': 'SA Western Standard Time', 'America/Belem': 'SA Eastern Standard Time', 'America/Belize': 'Central America Standard Time', 'America/Blanc-Sablon': 'SA Western Standard Time', 'America/Boa_Vista': 'SA Western Standard Time', 'America/Bogota': 'SA Pacific Standard Time', 'America/Boise': 'Mountain Standard Time', 'America/Buenos_Aires': 'Argentina Standard Time', 'America/Cambridge_Bay': 'Mountain Standard Time', 'America/Campo_Grande': 'Central Brazilian Standard Time', 'America/Cancun': 'Central Standard Time (Mexico)', 'America/Caracas': 'Venezuela Standard Time', 'America/Catamarca': 'Argentina Standard Time', 'America/Cayenne': 'SA Eastern Standard Time', 'America/Cayman': 'SA Pacific Standard Time', 'America/Chicago': 'Central Standard Time', 'America/Chihuahua': 'Mountain Standard Time (Mexico)', 'America/Coral_Harbour': 'SA Pacific Standard Time', 'America/Cordoba': 'Argentina Standard Time', 'America/Costa_Rica': 'Central America Standard Time', 'America/Creston': 'US Mountain Standard Time', 'America/Cuiaba': 'Central Brazilian Standard Time', 'America/Curacao': 'SA Western Standard Time', 'America/Danmarkshavn': 'UTC', 'America/Dawson': 'Pacific Standard Time', 'America/Dawson_Creek': 'US Mountain Standard Time', 'America/Denver': 'Mountain Standard Time', 'America/Detroit': 'Eastern Standard Time', 'America/Dominica': 'SA Western Standard Time', 'America/Edmonton': 'Mountain Standard Time', 'America/Eirunepe': 'SA Pacific Standard Time', 'America/El_Salvador': 'Central America Standard Time', 'America/Fortaleza': 'SA Eastern 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/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/Hermosillo': 'US Mountain Standard Time', 'America/Indiana/Knox': 'Central Standard Time', 'America/Indiana/Marengo': 'US Eastern Standard Time', 'America/Indiana/Petersburg': 'Eastern Standard Time', 'America/Indiana/Tell_City': 'Central Standard Time', 'America/Indiana/Vevay': 'US Eastern Standard Time', 'America/Indiana/Vincennes': 'Eastern Standard Time', 'America/Indiana/Winamac': 'Eastern Standard Time', 'America/Indianapolis': 'US Eastern Standard Time', 'America/Inuvik': 'Mountain Standard Time', 'America/Iqaluit': 'Eastern Standard Time', 'America/Jamaica': 'SA Pacific Standard Time', 'America/Jujuy': 'Argentina Standard Time', 'America/Juneau': 'Alaskan Standard Time', 'America/Kentucky/Monticello': 'Eastern Standard Time', 'America/Kralendijk': 'SA Western Standard Time', 'America/La_Paz': 'SA Western Standard Time', 'America/Lima': 'SA Pacific Standard Time', 'America/Los_Angeles': 'Pacific Standard Time', 'America/Louisville': 'Eastern Standard Time', 'America/Lower_Princes': 'SA Western Standard Time', 'America/Maceio': 'SA Eastern Standard Time', 'America/Managua': 'Central America Standard Time', 'America/Manaus': 'SA Western Standard Time', 'America/Marigot': 'SA Western Standard Time', 'America/Martinique': 'SA Western Standard Time', 'America/Matamoros': 'Central Standard Time', 'America/Mazatlan': 'Mountain Standard Time (Mexico)', 'America/Mendoza': 'Argentina Standard Time', 'America/Menominee': 'Central Standard Time', 'America/Merida': 'Central Standard Time (Mexico)', 'America/Mexico_City': 'Central Standard Time (Mexico)', 'America/Moncton': 'Atlantic Standard Time', 'America/Monterrey': 'Central Standard Time (Mexico)', 'America/Montevideo': 'Montevideo Standard Time', 'America/Montreal': 'Eastern Standard Time', 'America/Montserrat': 'SA Western Standard Time', 'America/Nassau': 'Eastern Standard Time', 'America/New_York': 'Eastern Standard Time', 'America/Nipigon': 'Eastern Standard Time', 'America/Nome': 'Alaskan Standard Time', 'America/Noronha': 'UTC-02', 'America/North_Dakota/Beulah': 'Central Standard Time', 'America/North_Dakota/Center': 'Central Standard Time', 'America/North_Dakota/New_Salem': 'Central Standard Time', 'America/Ojinaga': 'Mountain Standard Time', 'America/Panama': 'SA Pacific 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_of_Spain': 'SA Western Standard Time', 'America/Porto_Velho': 'SA Western Standard Time', 'America/Puerto_Rico': 'SA Western 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 (Mexico)', 'America/Santarem': 'SA Eastern Standard Time', 'America/Santiago': 'Pacific SA Standard Time', 'America/Santo_Domingo': 'SA Western Standard Time', 'America/Sao_Paulo': 'E. South America Standard Time', 'America/Scoresbysund': 'Azores Standard Time', 'America/Sitka': 'Alaskan Standard Time', 'America/St_Barthelemy': 'SA Western Standard Time', 'America/St_Johns': 'Newfoundland Standard Time', 'America/St_Kitts': 'SA Western Standard Time', 'America/St_Lucia': 'SA Western Standard Time', 'America/St_Thomas': 'SA Western Standard Time', 'America/St_Vincent': 'SA Western Standard Time', 'America/Swift_Current': 'Canada Central 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/Toronto': 'Eastern Standard Time', 'America/Tortola': 'SA Western Standard Time', 'America/Vancouver': 'Pacific Standard Time', 'America/Whitehorse': 'Pacific Standard Time', 'America/Winnipeg': 'Central Standard Time', 'America/Yakutat': 'Alaskan Standard Time', 'America/Yellowknife': 'Mountain Standard Time', 'Antarctica/Casey': 'W. Australia 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/Rothera': 'SA Eastern Standard Time', 'Antarctica/Syowa': 'E. Africa Standard Time', 'Antarctica/Vostok': 'Central Asia Standard Time', 'Arctic/Longyearbyen': 'W. Europe Standard Time', 'Asia/Aden': 'Arab Standard Time', 'Asia/Almaty': 'Central Asia Standard Time', 'Asia/Amman': 'Jordan Standard Time', 'Asia/Anadyr': 'Russia Time Zone 11', 'Asia/Aqtau': 'West Asia Standard Time', 'Asia/Aqtobe': 'West Asia Standard Time', 'Asia/Ashgabat': '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/Beirut': 'Middle East Standard Time', 'Asia/Bishkek': 'Central Asia Standard Time', 'Asia/Brunei': 'Singapore Standard Time', 'Asia/Calcutta': 'India Standard Time', 'Asia/Chita': 'North Asia East Standard Time', 'Asia/Choibalsan': 'Ulaanbaatar Standard Time', 'Asia/Colombo': 'Sri Lanka Standard Time', 'Asia/Damascus': 'Syria Standard Time', 'Asia/Dhaka': 'Bangladesh Standard Time', 'Asia/Dili': 'Tokyo Standard Time', 'Asia/Dubai': 'Arabian Standard Time', 'Asia/Dushanbe': 'West Asia Standard Time', 'Asia/Hong_Kong': 'China Standard Time', 'Asia/Hovd': 'SE Asia Standard Time', 'Asia/Irkutsk': 'North Asia East Standard Time', 'Asia/Jakarta': 'SE Asia Standard Time', 'Asia/Jayapura': 'Tokyo Standard Time', 'Asia/Jerusalem': 'Israel Standard Time', 'Asia/Kabul': 'Afghanistan Standard Time', 'Asia/Kamchatka': 'Russia Time Zone 11', 'Asia/Karachi': 'Pakistan Standard Time', 'Asia/Katmandu': 'Nepal Standard Time', 'Asia/Khandyga': 'Yakutsk Standard Time', 'Asia/Krasnoyarsk': 'North Asia Standard Time', 'Asia/Kuala_Lumpur': 'Singapore Standard Time', 'Asia/Kuching': 'Singapore Standard Time', 'Asia/Kuwait': 'Arab Standard Time', 'Asia/Macau': 'China Standard Time', 'Asia/Magadan': 'Magadan Standard Time', 'Asia/Makassar': 'Singapore Standard Time', 'Asia/Manila': 'Singapore Standard Time', 'Asia/Muscat': 'Arabian 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/Oral': 'West Asia Standard Time', 'Asia/Phnom_Penh': 'SE Asia Standard Time', 'Asia/Pontianak': 'SE Asia Standard Time', 'Asia/Pyongyang': 'Korea Standard Time', 'Asia/Qatar': 'Arab Standard Time', 'Asia/Qyzylorda': 'Central Asia Standard Time', 'Asia/Rangoon': 'Myanmar Standard Time', 'Asia/Riyadh': 'Arab Standard Time', 'Asia/Saigon': 'SE Asia Standard Time', 'Asia/Sakhalin': 'Vladivostok Standard Time', 'Asia/Samarkand': 'West Asia Standard Time', 'Asia/Seoul': 'Korea Standard Time', 'Asia/Shanghai': 'China Standard Time', 'Asia/Singapore': 'Singapore Standard Time', 'Asia/Srednekolymsk': 'Russia Time Zone 10', 'Asia/Taipei': 'Taipei Standard Time', 'Asia/Tashkent': 'West Asia Standard Time', 'Asia/Tbilisi': 'Georgian Standard Time', 'Asia/Tehran': 'Iran Standard Time', 'Asia/Thimphu': 'Bangladesh Standard Time', 'Asia/Tokyo': 'Tokyo Standard Time', 'Asia/Ulaanbaatar': 'Ulaanbaatar Standard Time', 'Asia/Urumqi': 'Central Asia Standard Time', 'Asia/Ust-Nera': 'Vladivostok Standard Time', 'Asia/Vientiane': 'SE Asia Standard Time', 'Asia/Vladivostok': 'Vladivostok Standard Time', 'Asia/Yakutsk': 'Yakutsk Standard Time', 'Asia/Yekaterinburg': 'Ekaterinburg Standard Time', 'Asia/Yerevan': 'Caucasus Standard Time', 'Atlantic/Azores': 'Azores Standard Time', 'Atlantic/Bermuda': 'Atlantic Standard Time', 'Atlantic/Canary': 'GMT Standard Time', 'Atlantic/Cape_Verde': 'Cape Verde Standard Time', 'Atlantic/Faeroe': 'GMT Standard Time', 'Atlantic/Madeira': 'GMT Standard Time', 'Atlantic/Reykjavik': 'Greenwich Standard Time', 'Atlantic/South_Georgia': 'UTC-02', 'Atlantic/St_Helena': 'Greenwich Standard Time', 'Atlantic/Stanley': 'SA Eastern Standard Time', 'Australia/Adelaide': 'Cen. Australia Standard Time', 'Australia/Brisbane': 'E. Australia Standard Time', 'Australia/Broken_Hill': 'Cen. Australia Standard Time', 'Australia/Currie': 'Tasmania Standard Time', 'Australia/Darwin': 'AUS Central Standard Time', 'Australia/Hobart': 'Tasmania Standard Time', 'Australia/Lindeman': 'E. Australia Standard Time', 'Australia/Melbourne': 'AUS Eastern Standard Time', 'Australia/Perth': 'W. Australia Standard Time', 'Australia/Sydney': 'AUS Eastern Standard Time', 'CST6CDT': 'Central Standard Time', 'EST5EDT': 'Eastern Standard Time', 'Etc/GMT': 'UTC', 'Etc/GMT+1': 'Cape Verde Standard Time', 'Etc/GMT+10': 'Hawaiian Standard Time', 'Etc/GMT+11': 'UTC-11', 'Etc/GMT+12': 'Dateline Standard Time', 'Etc/GMT+2': 'UTC-02', 'Etc/GMT+3': 'SA Eastern Standard Time', 'Etc/GMT+4': 'SA Western 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-1': 'W. Central Africa Standard Time', 'Etc/GMT-10': 'West Pacific Standard Time', 'Etc/GMT-11': 'Central Pacific Standard Time', 'Etc/GMT-12': 'UTC+12', 'Etc/GMT-13': 'Tonga Standard Time', 'Etc/GMT-14': 'Line Islands Standard Time', 'Etc/GMT-2': 'South Africa Standard Time', 'Etc/GMT-3': 'E. Africa Standard Time', 'Etc/GMT-4': 'Arabian Standard Time', 'Etc/GMT-5': 'West Asia Standard Time', 'Etc/GMT-6': 'Central Asia Standard Time', 'Etc/GMT-7': 'SE Asia Standard Time', 'Etc/GMT-8': 'Singapore Standard Time', 'Etc/GMT-9': 'Tokyo Standard Time', 'Etc/UTC': 'UTC', 'Europe/Amsterdam': 'W. Europe Standard Time', 'Europe/Andorra': 'W. Europe Standard Time', 'Europe/Athens': 'GTB Standard Time', 'Europe/Belgrade': 'Central Europe Standard Time', 'Europe/Berlin': 'W. Europe Standard Time', 'Europe/Bratislava': 'Central Europe Standard Time', 'Europe/Brussels': 'Romance Standard Time', 'Europe/Bucharest': 'GTB Standard Time', 'Europe/Budapest': 'Central Europe Standard Time', 'Europe/Busingen': 'W. Europe Standard Time', 'Europe/Chisinau': 'GTB Standard Time', 'Europe/Copenhagen': 'Romance Standard Time', 'Europe/Dublin': 'GMT Standard Time', 'Europe/Gibraltar': 'W. Europe Standard Time', 'Europe/Guernsey': 'GMT Standard Time', 'Europe/Helsinki': 'FLE Standard Time', 'Europe/Isle_of_Man': 'GMT Standard Time', 'Europe/Istanbul': 'Turkey Standard Time', 'Europe/Jersey': 'GMT Standard Time', 'Europe/Kaliningrad': 'Kaliningrad Standard Time', 'Europe/Kiev': 'FLE Standard Time', 'Europe/Lisbon': 'GMT Standard Time', 'Europe/Ljubljana': 'Central Europe Standard Time', 'Europe/London': 'GMT Standard Time', 'Europe/Luxembourg': 'W. Europe Standard Time', 'Europe/Madrid': 'Romance Standard Time', 'Europe/Malta': 'W. Europe Standard Time', 'Europe/Mariehamn': 'FLE Standard Time', 'Europe/Minsk': 'Belarus Standard Time', 'Europe/Monaco': 'W. Europe Standard Time', 'Europe/Moscow': 'Russian Standard Time', 'Europe/Oslo': 'W. Europe Standard Time', 'Europe/Paris': 'Romance Standard Time', 'Europe/Podgorica': 'Central Europe Standard Time', 'Europe/Prague': 'Central Europe Standard Time', 'Europe/Riga': 'FLE Standard Time', 'Europe/Rome': 'W. Europe Standard Time', 'Europe/Samara': 'Russia Time Zone 3', 'Europe/San_Marino': 'W. Europe Standard Time', 'Europe/Sarajevo': 'Central European 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/Uzhgorod': 'FLE Standard Time', 'Europe/Vaduz': 'W. Europe Standard Time', 'Europe/Vatican': 'W. Europe Standard Time', 'Europe/Vienna': 'W. Europe Standard Time', 'Europe/Vilnius': 'FLE Standard Time', 'Europe/Volgograd': 'Russian Standard Time', 'Europe/Warsaw': 'Central European Standard Time', 'Europe/Zagreb': 'Central European Standard Time', 'Europe/Zaporozhye': 'FLE Standard Time', 'Europe/Zurich': 'W. Europe Standard Time', 'Indian/Antananarivo': 'E. Africa Standard Time', 'Indian/Chagos': 'Central Asia Standard Time', 'Indian/Christmas': 'SE Asia Standard Time', 'Indian/Cocos': 'Myanmar Standard Time', 'Indian/Comoro': 'E. Africa Standard Time', 'Indian/Kerguelen': 'West Asia Standard Time', 'Indian/Mahe': 'Mauritius Standard Time', 'Indian/Maldives': 'West Asia Standard Time', 'Indian/Mauritius': 'Mauritius Standard Time', 'Indian/Mayotte': 'E. Africa Standard Time', 'Indian/Reunion': 'Mauritius Standard Time', 'MST7MDT': 'Mountain Standard Time', 'PST8PDT': 'Pacific Standard Time', 'Pacific/Apia': 'Samoa Standard Time', 'Pacific/Auckland': 'New Zealand 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/Guadalcanal': 'Central Pacific Standard Time', 'Pacific/Guam': 'West Pacific Standard Time', 'Pacific/Honolulu': 'Hawaiian Standard Time', 'Pacific/Johnston': 'Hawaiian Standard Time', 'Pacific/Kiritimati': 'Line Islands Standard Time', 'Pacific/Kosrae': 'Central Pacific Standard Time', 'Pacific/Kwajalein': 'UTC+12', 'Pacific/Majuro': 'UTC+12', 'Pacific/Midway': 'UTC-11', 'Pacific/Nauru': 'UTC+12', 'Pacific/Niue': 'UTC-11', 'Pacific/Noumea': 'Central Pacific Standard Time', 'Pacific/Pago_Pago': 'UTC-11', 'Pacific/Palau': 'Tokyo Standard Time', 'Pacific/Ponape': 'Central Pacific Standard Time', 'Pacific/Port_Moresby': 'West Pacific Standard Time', 'Pacific/Rarotonga': 'Hawaiian Standard Time', 'Pacific/Saipan': 'West Pacific Standard Time', 'Pacific/Tahiti': 'Hawaiian Standard Time', 'Pacific/Tarawa': 'UTC+12', 'Pacific/Tongatapu': 'Tonga Standard Time', 'Pacific/Truk': 'West Pacific Standard Time', 'Pacific/Wake': 'UTC+12', 'Pacific/Wallis': 'UTC+12'} tzlocal-1.2/tzlocal/unix.py0000664000175000017500000001073712537263222017473 0ustar lregebrolregebro00000000000000from __future__ import with_statement import os import re import pytz _cache_tz = None def _tz_from_env(tzenv): if tzenv[0] == ':': tzenv = tzenv[1:] # TZ specifies a file if os.path.exists(tzenv): with open(tzenv, 'rb') as tzfile: return pytz.tzfile.build_tzinfo('local', tzfile) # TZ specifies a zoneinfo zone. try: tz = pytz.timezone(tzenv) # That worked, so we return this: return tz except pytz.UnknownTimeZoneError: raise pytz.UnknownTimeZoneError( "tzlocal() does not support non-zoneinfo timezones like %s. \n" "Please use a timezone in the form of Continent/City") def _get_localzone(_root='/'): """Tries to find the local timezone configuration. This method prefers finding the timezone name and passing that to pytz, over passing in the localtime file, as in the later case the zoneinfo name is unknown. The parameter _root makes the function look for files like /etc/localtime beneath the _root directory. This is primarily used by the tests. In normal usage you call the function without parameters.""" tzenv = os.environ.get('TZ') if tzenv: try: return _tz_from_env(tzenv) except pytz.UnknownTimeZoneError: pass # 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() # 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 # Gentoo has a TIMEZONE setting in /etc/conf.d/clock # We look through these files for a timezone: zone_re = re.compile('\s*ZONE\s*=\s*\"') timezone_re = re.compile('\s*TIMEZONE\s*=\s*\"') end_re = re.compile('\"') for filename in ('etc/sysconfig/clock', 'etc/conf.d/clock'): tzpath = os.path.join(_root, filename) if not os.path.exists(tzpath): continue with open(tzpath, 'rt') as tzfile: data = tzfile.readlines() for line in data: # Look for the ZONE= setting. match = zone_re.match(line) if match is None: # No ZONE= setting. Look for the TIMEZONE= setting. match = timezone_re.match(line) if match is not None: # Some setting existed line = line[match.end():] etctz = line[:end_re.search(line).start()] # We found a timezone return pytz.timezone(etctz.replace(' ', '_')) # systemd distributions use symlinks that include the zone name, # see manpage of localtime(5) and timedatectl(1) tzpath = os.path.join(_root, 'etc/localtime') if os.path.exists(tzpath) and os.path.islink(tzpath): tzpath = os.path.realpath(tzpath) start = tzpath.find("/")+1 while start is not 0: tzpath = tzpath[start:] try: return pytz.timezone(tzpath) except pytz.UnknownTimeZoneError: pass start = tzpath.find("/")+1 # No explicit setting existed. Use localtime for filename in ('etc/localtime', 'usr/local/etc/localtime'): tzpath = os.path.join(_root, filename) if not os.path.exists(tzpath): continue with open(tzpath, 'rb') as tzfile: return pytz.tzfile.build_tzinfo('local', tzfile) raise pytz.UnknownTimeZoneError('Can not find any timezone configuration') def get_localzone(): """Get the computers configured local timezone, if any.""" global _cache_tz if _cache_tz is None: _cache_tz = _get_localzone() return _cache_tz def reload_localzone(): """Reload the cached localzone. You need to call this if the timezone has changed.""" global _cache_tz _cache_tz = _get_localzone() return _cache_tz tzlocal-1.2/tzlocal/test_data/0000775000175000017500000000000012537263230020075 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/zone_setting/0000775000175000017500000000000012537263230022605 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/zone_setting/etc/0000775000175000017500000000000012537263230023360 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/zone_setting/etc/sysconfig/0000775000175000017500000000000012537263230025364 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/zone_setting/etc/sysconfig/clock0000664000175000017500000000002512537263222026400 0ustar lregebrolregebro00000000000000ZONE="Africa/Harare" tzlocal-1.2/tzlocal/test_data/symlink_localtime/0000775000175000017500000000000012537263230023614 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/symlink_localtime/etc/0000775000175000017500000000000012537263230024367 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/symlink_localtime/etc/localtime0000777000175000017500000000000012537263222034546 2../usr/share/zoneinfo/Africa/Harareustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/symlink_localtime/usr/0000775000175000017500000000000012537263230024425 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/symlink_localtime/usr/share/0000775000175000017500000000000012537263230025527 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/symlink_localtime/usr/share/zoneinfo/0000775000175000017500000000000012537263230027356 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/symlink_localtime/usr/share/zoneinfo/Africa/0000775000175000017500000000000012537263230030543 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/symlink_localtime/usr/share/zoneinfo/Africa/Harare0000664000175000017500000000023512537263222031671 0ustar lregebrolregebro00000000000000TZif2‚FÇd LMTCATTZif2ÿÿÿÿ‚FÇd LMTCAT CAT-2 tzlocal-1.2/tzlocal/test_data/timezone/0000775000175000017500000000000012537263230021727 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/timezone/etc/0000775000175000017500000000000012537263230022502 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/timezone/etc/timezone0000664000175000017500000000001612537263222024255 0ustar lregebrolregebro00000000000000Africa/Harare tzlocal-1.2/tzlocal/test_data/localtime/0000775000175000017500000000000012537263230022046 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/localtime/etc/0000775000175000017500000000000012537263230022621 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/localtime/etc/localtime0000664000175000017500000000023512537263222024516 0ustar lregebrolregebro00000000000000TZif2‚FÇd LMTCATTZif2ÿÿÿÿ‚FÇd LMTCAT CAT-2 tzlocal-1.2/tzlocal/test_data/Harare0000664000175000017500000000023512537263222021223 0ustar lregebrolregebro00000000000000TZif2‚FÇd LMTCATTZif2ÿÿÿÿ‚FÇd LMTCAT CAT-2 tzlocal-1.2/tzlocal/test_data/timezone_setting/0000775000175000017500000000000012537263230023464 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/timezone_setting/etc/0000775000175000017500000000000012537263230024237 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/timezone_setting/etc/conf.d/0000775000175000017500000000000012537263230025406 5ustar lregebrolregebro00000000000000tzlocal-1.2/tzlocal/test_data/timezone_setting/etc/conf.d/clock0000664000175000017500000000003312537263222026421 0ustar lregebrolregebro00000000000000TIMEZONE = "Africa/Harare" tzlocal-1.2/tzlocal/win32.py0000664000175000017500000000607712537263222017454 0ustar lregebrolregebro00000000000000try: import _winreg as winreg except ImportError: import winreg from tzlocal.windows_tz import win_tz import pytz _cache_tz = None def valuestodict(key): """Convert a registry key's values to a dictionary.""" dict = {} size = winreg.QueryInfoKey(key)[1] for i in range(size): data = winreg.EnumValue(key, i) dict[data[0]] = data[1] return dict def get_localzone_name(): # Windows is special. It has unique time zone names (in several # meanings of the word) available, but unfortunately, they can be # translated to the language of the operating system, so we need to # do a backwards lookup, by going through all time zones and see which # one matches. handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) TZLOCALKEYNAME = r"SYSTEM\CurrentControlSet\Control\TimeZoneInformation" localtz = winreg.OpenKey(handle, TZLOCALKEYNAME) keyvalues = valuestodict(localtz) localtz.Close() if 'TimeZoneKeyName' in keyvalues: # Windows 7 (and Vista?) # For some reason this returns a string with loads of NUL bytes at # least on some systems. I don't know if this is a bug somewhere, I # just work around it. tzkeyname = keyvalues['TimeZoneKeyName'].split('\x00', 1)[0] else: # Windows 2000 or XP # This is the localized name: tzwin = keyvalues['StandardName'] # Open the list of timezones to look up the real name: TZKEYNAME = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones" tzkey = winreg.OpenKey(handle, TZKEYNAME) # Now, match this value to Time Zone information tzkeyname = None for i in range(winreg.QueryInfoKey(tzkey)[0]): subkey = winreg.EnumKey(tzkey, i) sub = winreg.OpenKey(tzkey, subkey) data = valuestodict(sub) sub.Close() try: if data['Std'] == tzwin: tzkeyname = subkey break except KeyError: # This timezone didn't have proper configuration. # Ignore it. pass tzkey.Close() handle.Close() if tzkeyname is None: raise LookupError('Can not find Windows timezone configuration') timezone = win_tz.get(tzkeyname) if timezone is None: # Nope, that didn't work. Try adding "Standard Time", # it seems to work a lot of times: timezone = win_tz.get(tzkeyname + " Standard Time") # Return what we have. if timezone is None: raise pytz.UnknownTimeZoneError('Can not find timezone ' + tzkeyname) return timezone def get_localzone(): """Returns the zoneinfo-based tzinfo object that matches the Windows-configured timezone.""" global _cache_tz if _cache_tz is None: _cache_tz = pytz.timezone(get_localzone_name()) return _cache_tz def reload_localzone(): """Reload the cached localzone. You need to call this if the timezone has changed.""" global _cache_tz _cache_tz = pytz.timezone(get_localzone_name()) tzlocal-1.2/tzlocal/tests.py0000664000175000017500000000554312537263222017651 0ustar lregebrolregebro00000000000000import sys import os from datetime import datetime import unittest import pytz import tzlocal.unix class TzLocalTests(unittest.TestCase): def test_env(self): tz_harare = tzlocal.unix._tz_from_env(':Africa/Harare') self.assertEqual(tz_harare.zone, 'Africa/Harare') # Some Unices allow this as well, so we must allow it: tz_harare = tzlocal.unix._tz_from_env('Africa/Harare') self.assertEqual(tz_harare.zone, 'Africa/Harare') local_path = os.path.split(__file__)[0] tz_local = tzlocal.unix._tz_from_env(':' + os.path.join(local_path, 'test_data', 'Harare')) self.assertEqual(tz_local.zone, 'local') # Make sure the local timezone is the same as the Harare one above. # We test this with a past date, so that we don't run into future changes # of the Harare timezone. dt = datetime(2012, 1, 1, 5) self.assertEqual(tz_harare.localize(dt), tz_local.localize(dt)) # Non-zoneinfo timezones are not supported in the TZ environment. self.assertRaises(pytz.UnknownTimeZoneError, tzlocal.unix._tz_from_env, 'GMT+03:00') def test_timezone(self): # Most versions of Ubuntu local_path = os.path.split(__file__)[0] tz = tzlocal.unix._get_localzone(_root=os.path.join(local_path, 'test_data', 'timezone')) self.assertEqual(tz.zone, 'Africa/Harare') def test_zone_setting(self): # A ZONE setting in /etc/sysconfig/clock, f ex CentOS local_path = os.path.split(__file__)[0] tz = tzlocal.unix._get_localzone(_root=os.path.join(local_path, 'test_data', 'zone_setting')) self.assertEqual(tz.zone, 'Africa/Harare') def test_timezone_setting(self): # A ZONE setting in /etc/conf.d/clock, f ex Gentoo local_path = os.path.split(__file__)[0] tz = tzlocal.unix._get_localzone(_root=os.path.join(local_path, 'test_data', 'timezone_setting')) self.assertEqual(tz.zone, 'Africa/Harare') def test_symlink_localtime(self): # A ZONE setting in the target path of a symbolic linked localtime, f ex systemd distributions local_path = os.path.split(__file__)[0] tz = tzlocal.unix._get_localzone(_root=os.path.join(local_path, 'test_data', 'symlink_localtime')) self.assertEqual(tz.zone, 'Africa/Harare') def test_only_localtime(self): local_path = os.path.split(__file__)[0] tz = tzlocal.unix._get_localzone(_root=os.path.join(local_path, 'test_data', 'localtime')) self.assertEqual(tz.zone, 'local') dt = datetime(2012, 1, 1, 5) self.assertEqual(pytz.timezone('Africa/Harare').localize(dt), tz.localize(dt)) if sys.platform == 'win32': import tzlocal.win32 class TzWin32Tests(unittest.TestCase): def test_win32(self): tzlocal.win32.get_localzone() if __name__ == '__main__': unittest.main() tzlocal-1.2/tzlocal/__init__.py0000664000175000017500000000040612537263222020237 0ustar lregebrolregebro00000000000000import sys if sys.platform == 'win32': from tzlocal.win32 import get_localzone, reload_localzone elif 'darwin' in sys.platform: from tzlocal.darwin import get_localzone, reload_localzone else: from tzlocal.unix import get_localzone, reload_localzone tzlocal-1.2/LICENSE.txt0000664000175000017500000001561012537263222016304 0ustar lregebrolregebro00000000000000Creative Commons Legal Code CC0 1.0 Universal CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER. Statement of Purpose The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work"). Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others. For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights. 1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following: i. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work; ii. moral rights retained by the original author(s) and/or performer(s); iii. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work; iv. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below; v. rights protecting the extraction, dissemination, use and reuse of data in a Work; vi. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and vii. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof. 2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose. 3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose. 4. Limitations and Disclaimers. a. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document. b. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law. c. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work. d. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work. tzlocal-1.2/MANIFEST.in0000664000175000017500000000011612537263222016212 0ustar lregebrolregebro00000000000000include *.py include *.rst include *.txt recursive-include tzlocal/test_data *tzlocal-1.2/get_windows_info.py0000664000175000017500000000261212537263222020375 0ustar lregebrolregebro00000000000000# This script generates the mapping between MS Windows timezone names and # tzdata/Olsen timezone names, by retrieving a file: # http://unicode.org/cldr/data/common/supplemental/supplementalData.xml # and parsing it, and from this generating the file windows_tz.py. # # It must be run with Python 3. XML_SOURCE = 'http://unicode.org/cldr/data/common/supplemental/windowsZones.xml' from urllib.request import urlopen from xml.dom import minidom from pprint import pprint source = urlopen(XML_SOURCE).read() dom = minidom.parseString(source) for element in dom.getElementsByTagName('mapTimezones'): if element.getAttribute('type') == 'windows': break win_tz = {} tz_win = {} for mapping in element.getElementsByTagName('mapZone'): if mapping.getAttribute('territory') == '001': win_tz[mapping.getAttribute('other')] = mapping.getAttribute('type').split(' ')[0] for tz_name in mapping.getAttribute('type').split(' '): tz_win[tz_name] = mapping.getAttribute('other') # Etc/UTC is a common alias for Etc/GMT: tz_win['Etc/UTC'] = 'UTC' with open('tzlocal/windows_tz.py', "wt") as out: out.write("# This file is autogenerated by the get_windows_info.py script\n" "# Do not edit.\nwin_tz = ") pprint(win_tz, out) out.write("\n# Old name for the win_tz variable:\ntz_names = win_tz\n\ntz_win = ") pprint(tz_win, out) tzlocal-1.2/setup.cfg0000664000175000017500000000014112537263230016272 0ustar lregebrolregebro00000000000000[check-manifest] ignore = spiny.conf [egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 tzlocal-1.2/setup.py0000664000175000017500000000260712537263222016175 0ustar lregebrolregebro00000000000000from setuptools import setup, find_packages import sys, os version = '1.2' setup(name='tzlocal', version=version, description="tzinfo object for the local timezone", long_description=open('README.rst', 'rt').read() + '\n\n' + open('CHANGES.txt', 'rt').read(), classifiers=[ 'Development Status :: 4 - Beta', 'License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication', 'Operating System :: Microsoft :: Windows', 'Operating System :: Unix', 'Operating System :: MacOS :: MacOS X', 'Programming Language :: Python :: 2.5', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.1', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', ], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers keywords='timezone pytz', author='Lennart Regebro', author_email='regebro@gmail.com', url='https://github.com/regebro/tzlocal', license='CC0 1.0 Universal', packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), include_package_data=True, zip_safe=True, install_requires=[ 'pytz', ], test_suite='tzlocal.tests', )