1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
From: Benjamin Drung <benjamin.drung@canonical.com>
Date: Mon, 20 Mar 2023 17:49:11 +0100
Subject: Dynamically determine list of available and common timezones
The Debian/Ubuntu packages of pytz include a patch to not install pytz's
zoneinfo database and instead load data from the system zoneinfo
database. This keeps pytz up to date when system timezone updates are
installed which is generally a good idea.
The `pytz/__init__.py` includes `common_timezones` and `all_timezones`
lists, which enumerate the time zones in the database pytz was released
with. If pytz is instead using the system database, these lists may not
be correct (e.g. missing newly added time zones).
Dynamically determine `all_timezones` and `common_timezones`. For
`all_timezones` use `zoneinfo` from Python 3.9 and for
`common_timezones` parse `/usr/share/zoneinfo/zone1970.tab`.
Bug: https://launchpad.net/bugs/207604
Forwarded: not-needed
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
---
pytz/__init__.py | 941 ++-----------------------------------------------------
1 file changed, 21 insertions(+), 920 deletions(-)
Index: python-tz-2025.2/src/pytz/__init__.py
===================================================================
--- python-tz-2025.2.orig/src/pytz/__init__.py
+++ python-tz-2025.2/src/pytz/__init__.py
@@ -522,6 +522,134 @@ def _read_timezones_from_zone_tab() -> s
timezones.add(line.split("\t")[2])
return timezones
+_extra_common_timezones_set = {
+ 'Africa/Accra',
+ 'Africa/Addis_Ababa',
+ 'Africa/Asmara',
+ 'Africa/Bamako',
+ 'Africa/Bangui',
+ 'Africa/Banjul',
+ 'Africa/Blantyre',
+ 'Africa/Brazzaville',
+ 'Africa/Bujumbura',
+ 'Africa/Conakry',
+ 'Africa/Dakar',
+ 'Africa/Dar_es_Salaam',
+ 'Africa/Djibouti',
+ 'Africa/Douala',
+ 'Africa/Freetown',
+ 'Africa/Gaborone',
+ 'Africa/Harare',
+ 'Africa/Kampala',
+ 'Africa/Kigali',
+ 'Africa/Kinshasa',
+ 'Africa/Libreville',
+ 'Africa/Lome',
+ 'Africa/Luanda',
+ 'Africa/Lubumbashi',
+ 'Africa/Lusaka',
+ 'Africa/Malabo',
+ 'Africa/Maseru',
+ 'Africa/Mbabane',
+ 'Africa/Mogadishu',
+ 'Africa/Niamey',
+ 'Africa/Nouakchott',
+ 'Africa/Ouagadougou',
+ 'Africa/Porto-Novo',
+ 'America/Anguilla',
+ 'America/Antigua',
+ 'America/Aruba',
+ 'America/Atikokan',
+ 'America/Blanc-Sablon',
+ 'America/Cayman',
+ 'America/Creston',
+ 'America/Curacao',
+ 'America/Dominica',
+ 'America/Grenada',
+ 'America/Guadeloupe',
+ 'America/Kralendijk',
+ 'America/Lower_Princes',
+ 'America/Marigot',
+ 'America/Montserrat',
+ 'America/Nassau',
+ 'America/Port_of_Spain',
+ 'America/St_Barthelemy',
+ 'America/St_Kitts',
+ 'America/St_Lucia',
+ 'America/St_Thomas',
+ 'America/St_Vincent',
+ 'America/Tortola',
+ 'Antarctica/DumontDUrville',
+ 'Antarctica/McMurdo',
+ 'Antarctica/Syowa',
+ 'Antarctica/Vostok',
+ 'Arctic/Longyearbyen',
+ 'Asia/Aden',
+ 'Asia/Bahrain',
+ 'Asia/Kuala_Lumpur',
+ 'Asia/Kuwait',
+ 'Asia/Muscat',
+ 'Asia/Phnom_Penh',
+ 'Asia/Vientiane',
+ 'Atlantic/Reykjavik',
+ 'Atlantic/St_Helena',
+ 'Canada/Atlantic',
+ 'Canada/Central',
+ 'Canada/Eastern',
+ 'Canada/Mountain',
+ 'Canada/Newfoundland',
+'Canada/Pacific',
+ 'Europe/Amsterdam',
+ 'Europe/Bratislava',
+ 'Europe/Busingen',
+ 'Europe/Copenhagen',
+ 'Europe/Guernsey',
+ 'Europe/Isle_of_Man',
+ 'Europe/Jersey',
+ 'Europe/Ljubljana',
+ 'Europe/Luxembourg',
+ 'Europe/Mariehamn',
+ 'Europe/Monaco',
+ 'Europe/Oslo',
+ 'Europe/Podgorica',
+ 'Europe/San_Marino',
+ 'Europe/Sarajevo',
+ 'Europe/Skopje',
+ 'Europe/Stockholm',
+ 'Europe/Vaduz',
+ 'Europe/Vatican',
+ 'Europe/Zagreb',
+ 'GMT',
+ 'Indian/Antananarivo',
+ 'Indian/Christmas',
+ 'Indian/Cocos',
+ 'Indian/Comoro',
+ 'Indian/Kerguelen',
+ 'Indian/Mahe',
+ 'Indian/Mayotte',
+ 'Indian/Reunion',
+ 'Pacific/Chuuk',
+ 'Pacific/Funafuti',
+ 'Pacific/Majuro',
+ 'Pacific/Midway',
+ 'Pacific/Pohnpei',
+ 'Pacific/Saipan',
+ 'Pacific/Wake',
+ 'Pacific/Wallis',
+ 'US/Alaska',
+ 'US/Arizona',
+ 'US/Central',
+ 'US/Eastern',
+ 'US/Hawaii',
+ 'US/Mountain',
+ 'US/Pacific',
+ 'UTC'}
+
+all_timezones_set = zoneinfo.available_timezones() - {"Factory", "localtime"}
+common_timezones_set = (_read_timezones_from_zone_tab() | _extra_common_timezones_set) & all_timezones_set
+
+all_timezones = sorted(all_timezones_set)
+common_timezones = sorted(common_timezones_set)
if __name__ == '__main__':
_test()
|