Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/pytz-2025.1.dist-info/METADATA @ 69:33d812a61356
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 17:55:14 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 69:33d812a61356 |
---|---|
1 Metadata-Version: 2.1 | |
2 Name: pytz | |
3 Version: 2025.1 | |
4 Summary: World timezone definitions, modern and historical | |
5 Home-page: http://pythonhosted.org/pytz | |
6 Download-URL: https://pypi.org/project/pytz/ | |
7 Author: Stuart Bishop | |
8 Author-email: stuart@stuartbishop.net | |
9 Maintainer: Stuart Bishop | |
10 Maintainer-email: stuart@stuartbishop.net | |
11 License: MIT | |
12 Keywords: timezone,tzinfo,datetime,olson,time | |
13 Platform: Independent | |
14 Classifier: Development Status :: 6 - Mature | |
15 Classifier: Intended Audience :: Developers | |
16 Classifier: License :: OSI Approved :: MIT License | |
17 Classifier: Natural Language :: English | |
18 Classifier: Operating System :: OS Independent | |
19 Classifier: Programming Language :: Python | |
20 Classifier: Programming Language :: Python :: 2 | |
21 Classifier: Programming Language :: Python :: 2.4 | |
22 Classifier: Programming Language :: Python :: 2.5 | |
23 Classifier: Programming Language :: Python :: 2.6 | |
24 Classifier: Programming Language :: Python :: 2.7 | |
25 Classifier: Programming Language :: Python :: 3 | |
26 Classifier: Programming Language :: Python :: 3.1 | |
27 Classifier: Programming Language :: Python :: 3.2 | |
28 Classifier: Programming Language :: Python :: 3.3 | |
29 Classifier: Programming Language :: Python :: 3.4 | |
30 Classifier: Programming Language :: Python :: 3.5 | |
31 Classifier: Programming Language :: Python :: 3.6 | |
32 Classifier: Programming Language :: Python :: 3.7 | |
33 Classifier: Programming Language :: Python :: 3.8 | |
34 Classifier: Programming Language :: Python :: 3.9 | |
35 Classifier: Programming Language :: Python :: 3.10 | |
36 Classifier: Programming Language :: Python :: 3.11 | |
37 Classifier: Programming Language :: Python :: 3.12 | |
38 Classifier: Programming Language :: Python :: 3.13 | |
39 Classifier: Topic :: Software Development :: Libraries :: Python Modules | |
40 License-File: LICENSE.txt | |
41 | |
42 pytz - World Timezone Definitions for Python | |
43 ============================================ | |
44 | |
45 :Author: Stuart Bishop <stuart@stuartbishop.net> | |
46 | |
47 Introduction | |
48 ~~~~~~~~~~~~ | |
49 | |
50 pytz brings the Olson tz database into Python. This library allows | |
51 accurate and cross platform timezone calculations using Python 2.4 | |
52 or higher. It also solves the issue of ambiguous times at the end | |
53 of daylight saving time, which you can read more about in the Python | |
54 Library Reference (``datetime.tzinfo``). | |
55 | |
56 Almost all of the Olson timezones are supported. | |
57 | |
58 .. note:: | |
59 | |
60 Projects using Python 3.9 or later should be using the support | |
61 now included as part of the standard library, and third party | |
62 packages work with it such as `tzdata <https://pypi.org/project/tzdata/>`_. | |
63 pytz offers no advantages beyond backwards compatibility with | |
64 code written for earlier versions of Python. | |
65 | |
66 .. note:: | |
67 | |
68 This library differs from the documented Python API for | |
69 tzinfo implementations; if you want to create local wallclock | |
70 times you need to use the ``localize()`` method documented in this | |
71 document. In addition, if you perform date arithmetic on local | |
72 times that cross DST boundaries, the result may be in an incorrect | |
73 timezone (ie. subtract 1 minute from 2002-10-27 1:00 EST and you get | |
74 2002-10-27 0:59 EST instead of the correct 2002-10-27 1:59 EDT). A | |
75 ``normalize()`` method is provided to correct this. Unfortunately these | |
76 issues cannot be resolved without modifying the Python datetime | |
77 implementation (see PEP-431). | |
78 | |
79 | |
80 Installation | |
81 ~~~~~~~~~~~~ | |
82 | |
83 This package can either be installed using ``pip`` or from a tarball using the | |
84 standard Python distutils. | |
85 | |
86 If you are installing using ``pip``, you don't need to download anything as the | |
87 latest version will be downloaded for you from PyPI:: | |
88 | |
89 pip install pytz | |
90 | |
91 If you are installing from a tarball, run the following command as an | |
92 administrative user:: | |
93 | |
94 python setup.py install | |
95 | |
96 | |
97 pytz for Enterprise | |
98 ~~~~~~~~~~~~~~~~~~~ | |
99 | |
100 Available as part of the Tidelift Subscription. | |
101 | |
102 The maintainers of pytz and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. `Learn more. <https://tidelift.com/subscription/pkg/pypi-pytz?utm_source=pypi-pytz&utm_medium=referral&utm_campaign=enterprise&utm_term=repo>`_. | |
103 | |
104 | |
105 Example & Usage | |
106 ~~~~~~~~~~~~~~~ | |
107 | |
108 Localized times and date arithmetic | |
109 ----------------------------------- | |
110 | |
111 >>> from datetime import datetime, timedelta | |
112 >>> from pytz import timezone | |
113 >>> import pytz | |
114 >>> utc = pytz.utc | |
115 >>> utc.zone | |
116 'UTC' | |
117 >>> eastern = timezone('US/Eastern') | |
118 >>> eastern.zone | |
119 'US/Eastern' | |
120 >>> amsterdam = timezone('Europe/Amsterdam') | |
121 >>> fmt = '%Y-%m-%d %H:%M:%S %Z%z' | |
122 | |
123 This library only supports two ways of building a localized time. The | |
124 first is to use the ``localize()`` method provided by the pytz library. | |
125 This is used to localize a naive datetime (datetime with no timezone | |
126 information): | |
127 | |
128 >>> loc_dt = eastern.localize(datetime(2002, 10, 27, 6, 0, 0)) | |
129 >>> print(loc_dt.strftime(fmt)) | |
130 2002-10-27 06:00:00 EST-0500 | |
131 | |
132 The second way of building a localized time is by converting an existing | |
133 localized time using the standard ``astimezone()`` method: | |
134 | |
135 >>> ams_dt = loc_dt.astimezone(amsterdam) | |
136 >>> ams_dt.strftime(fmt) | |
137 '2002-10-27 12:00:00 CET+0100' | |
138 | |
139 Unfortunately using the tzinfo argument of the standard datetime | |
140 constructors ''does not work'' with pytz for many timezones. | |
141 | |
142 >>> datetime(2002, 10, 27, 12, 0, 0, tzinfo=amsterdam).strftime(fmt) # /!\ Does not work this way! | |
143 '2002-10-27 12:00:00 LMT+0018' | |
144 | |
145 It is safe for timezones without daylight saving transitions though, such | |
146 as UTC: | |
147 | |
148 >>> datetime(2002, 10, 27, 12, 0, 0, tzinfo=pytz.utc).strftime(fmt) # /!\ Not recommended except for UTC | |
149 '2002-10-27 12:00:00 UTC+0000' | |
150 | |
151 The preferred way of dealing with times is to always work in UTC, | |
152 converting to localtime only when generating output to be read | |
153 by humans. | |
154 | |
155 >>> utc_dt = datetime(2002, 10, 27, 6, 0, 0, tzinfo=utc) | |
156 >>> loc_dt = utc_dt.astimezone(eastern) | |
157 >>> loc_dt.strftime(fmt) | |
158 '2002-10-27 01:00:00 EST-0500' | |
159 | |
160 This library also allows you to do date arithmetic using local | |
161 times, although it is more complicated than working in UTC as you | |
162 need to use the ``normalize()`` method to handle daylight saving time | |
163 and other timezone transitions. In this example, ``loc_dt`` is set | |
164 to the instant when daylight saving time ends in the US/Eastern | |
165 timezone. | |
166 | |
167 >>> before = loc_dt - timedelta(minutes=10) | |
168 >>> before.strftime(fmt) | |
169 '2002-10-27 00:50:00 EST-0500' | |
170 >>> eastern.normalize(before).strftime(fmt) | |
171 '2002-10-27 01:50:00 EDT-0400' | |
172 >>> after = eastern.normalize(before + timedelta(minutes=20)) | |
173 >>> after.strftime(fmt) | |
174 '2002-10-27 01:10:00 EST-0500' | |
175 | |
176 Creating local times is also tricky, and the reason why working with | |
177 local times is not recommended. Unfortunately, you cannot just pass | |
178 a ``tzinfo`` argument when constructing a datetime (see the next | |
179 section for more details) | |
180 | |
181 >>> dt = datetime(2002, 10, 27, 1, 30, 0) | |
182 >>> dt1 = eastern.localize(dt, is_dst=True) | |
183 >>> dt1.strftime(fmt) | |
184 '2002-10-27 01:30:00 EDT-0400' | |
185 >>> dt2 = eastern.localize(dt, is_dst=False) | |
186 >>> dt2.strftime(fmt) | |
187 '2002-10-27 01:30:00 EST-0500' | |
188 | |
189 Converting between timezones is more easily done, using the | |
190 standard astimezone method. | |
191 | |
192 >>> utc_dt = datetime.fromtimestamp(1143408899, tz=utc) | |
193 >>> utc_dt.strftime(fmt) | |
194 '2006-03-26 21:34:59 UTC+0000' | |
195 >>> au_tz = timezone('Australia/Sydney') | |
196 >>> au_dt = utc_dt.astimezone(au_tz) | |
197 >>> au_dt.strftime(fmt) | |
198 '2006-03-27 08:34:59 AEDT+1100' | |
199 >>> utc_dt2 = au_dt.astimezone(utc) | |
200 >>> utc_dt2.strftime(fmt) | |
201 '2006-03-26 21:34:59 UTC+0000' | |
202 >>> utc_dt == utc_dt2 | |
203 True | |
204 | |
205 You can take shortcuts when dealing with the UTC side of timezone | |
206 conversions. ``normalize()`` and ``localize()`` are not really | |
207 necessary when there are no daylight saving time transitions to | |
208 deal with. | |
209 | |
210 >>> utc_dt = datetime.fromtimestamp(1143408899, tz=utc) | |
211 >>> utc_dt.strftime(fmt) | |
212 '2006-03-26 21:34:59 UTC+0000' | |
213 >>> au_tz = timezone('Australia/Sydney') | |
214 >>> au_dt = au_tz.normalize(utc_dt.astimezone(au_tz)) | |
215 >>> au_dt.strftime(fmt) | |
216 '2006-03-27 08:34:59 AEDT+1100' | |
217 >>> utc_dt2 = au_dt.astimezone(utc) | |
218 >>> utc_dt2.strftime(fmt) | |
219 '2006-03-26 21:34:59 UTC+0000' | |
220 | |
221 | |
222 ``tzinfo`` API | |
223 -------------- | |
224 | |
225 The ``tzinfo`` instances returned by the ``timezone()`` function have | |
226 been extended to cope with ambiguous times by adding an ``is_dst`` | |
227 parameter to the ``utcoffset()``, ``dst()`` && ``tzname()`` methods. | |
228 | |
229 >>> tz = timezone('America/St_Johns') | |
230 | |
231 >>> normal = datetime(2009, 9, 1) | |
232 >>> ambiguous = datetime(2009, 10, 31, 23, 30) | |
233 | |
234 The ``is_dst`` parameter is ignored for most timestamps. It is only used | |
235 during DST transition ambiguous periods to resolve that ambiguity. | |
236 | |
237 >>> print(tz.utcoffset(normal, is_dst=True)) | |
238 -1 day, 21:30:00 | |
239 >>> print(tz.dst(normal, is_dst=True)) | |
240 1:00:00 | |
241 >>> tz.tzname(normal, is_dst=True) | |
242 'NDT' | |
243 | |
244 >>> print(tz.utcoffset(ambiguous, is_dst=True)) | |
245 -1 day, 21:30:00 | |
246 >>> print(tz.dst(ambiguous, is_dst=True)) | |
247 1:00:00 | |
248 >>> tz.tzname(ambiguous, is_dst=True) | |
249 'NDT' | |
250 | |
251 >>> print(tz.utcoffset(normal, is_dst=False)) | |
252 -1 day, 21:30:00 | |
253 >>> tz.dst(normal, is_dst=False).seconds | |
254 3600 | |
255 >>> tz.tzname(normal, is_dst=False) | |
256 'NDT' | |
257 | |
258 >>> print(tz.utcoffset(ambiguous, is_dst=False)) | |
259 -1 day, 20:30:00 | |
260 >>> tz.dst(ambiguous, is_dst=False) | |
261 datetime.timedelta(0) | |
262 >>> tz.tzname(ambiguous, is_dst=False) | |
263 'NST' | |
264 | |
265 If ``is_dst`` is not specified, ambiguous timestamps will raise | |
266 an ``pytz.exceptions.AmbiguousTimeError`` exception. | |
267 | |
268 >>> print(tz.utcoffset(normal)) | |
269 -1 day, 21:30:00 | |
270 >>> print(tz.dst(normal)) | |
271 1:00:00 | |
272 >>> tz.tzname(normal) | |
273 'NDT' | |
274 | |
275 >>> import pytz.exceptions | |
276 >>> try: | |
277 ... tz.utcoffset(ambiguous) | |
278 ... except pytz.exceptions.AmbiguousTimeError: | |
279 ... print('pytz.exceptions.AmbiguousTimeError: %s' % ambiguous) | |
280 pytz.exceptions.AmbiguousTimeError: 2009-10-31 23:30:00 | |
281 >>> try: | |
282 ... tz.dst(ambiguous) | |
283 ... except pytz.exceptions.AmbiguousTimeError: | |
284 ... print('pytz.exceptions.AmbiguousTimeError: %s' % ambiguous) | |
285 pytz.exceptions.AmbiguousTimeError: 2009-10-31 23:30:00 | |
286 >>> try: | |
287 ... tz.tzname(ambiguous) | |
288 ... except pytz.exceptions.AmbiguousTimeError: | |
289 ... print('pytz.exceptions.AmbiguousTimeError: %s' % ambiguous) | |
290 pytz.exceptions.AmbiguousTimeError: 2009-10-31 23:30:00 | |
291 | |
292 | |
293 Problems with Localtime | |
294 ~~~~~~~~~~~~~~~~~~~~~~~ | |
295 | |
296 The major problem we have to deal with is that certain datetimes | |
297 may occur twice in a year. For example, in the US/Eastern timezone | |
298 on the last Sunday morning in October, the following sequence | |
299 happens: | |
300 | |
301 - 01:00 EDT occurs | |
302 - 1 hour later, instead of 2:00am the clock is turned back 1 hour | |
303 and 01:00 happens again (this time 01:00 EST) | |
304 | |
305 In fact, every instant between 01:00 and 02:00 occurs twice. This means | |
306 that if you try and create a time in the 'US/Eastern' timezone | |
307 the standard datetime syntax, there is no way to specify if you meant | |
308 before of after the end-of-daylight-saving-time transition. Using the | |
309 pytz custom syntax, the best you can do is make an educated guess: | |
310 | |
311 >>> loc_dt = eastern.localize(datetime(2002, 10, 27, 1, 30, 00)) | |
312 >>> loc_dt.strftime(fmt) | |
313 '2002-10-27 01:30:00 EST-0500' | |
314 | |
315 As you can see, the system has chosen one for you and there is a 50% | |
316 chance of it being out by one hour. For some applications, this does | |
317 not matter. However, if you are trying to schedule meetings with people | |
318 in different timezones or analyze log files it is not acceptable. | |
319 | |
320 The best and simplest solution is to stick with using UTC. The pytz | |
321 package encourages using UTC for internal timezone representation by | |
322 including a special UTC implementation based on the standard Python | |
323 reference implementation in the Python documentation. | |
324 | |
325 The UTC timezone unpickles to be the same instance, and pickles to a | |
326 smaller size than other pytz tzinfo instances. The UTC implementation | |
327 can be obtained as pytz.utc, pytz.UTC, or pytz.timezone('UTC'). | |
328 | |
329 >>> import pickle, pytz | |
330 >>> dt = datetime(2005, 3, 1, 14, 13, 21, tzinfo=utc) | |
331 >>> naive = dt.replace(tzinfo=None) | |
332 >>> p = pickle.dumps(dt, 1) | |
333 >>> naive_p = pickle.dumps(naive, 1) | |
334 >>> len(p) - len(naive_p) | |
335 17 | |
336 >>> new = pickle.loads(p) | |
337 >>> new == dt | |
338 True | |
339 >>> new is dt | |
340 False | |
341 >>> new.tzinfo is dt.tzinfo | |
342 True | |
343 >>> pytz.utc is pytz.UTC is pytz.timezone('UTC') | |
344 True | |
345 | |
346 Note that some other timezones are commonly thought of as the same (GMT, | |
347 Greenwich, Universal, etc.). The definition of UTC is distinct from these | |
348 other timezones, and they are not equivalent. For this reason, they will | |
349 not compare the same in Python. | |
350 | |
351 >>> utc == pytz.timezone('GMT') | |
352 False | |
353 | |
354 See the section `What is UTC`_, below. | |
355 | |
356 If you insist on working with local times, this library provides a | |
357 facility for constructing them unambiguously: | |
358 | |
359 >>> loc_dt = datetime(2002, 10, 27, 1, 30, 00) | |
360 >>> est_dt = eastern.localize(loc_dt, is_dst=True) | |
361 >>> edt_dt = eastern.localize(loc_dt, is_dst=False) | |
362 >>> print(est_dt.strftime(fmt) + ' / ' + edt_dt.strftime(fmt)) | |
363 2002-10-27 01:30:00 EDT-0400 / 2002-10-27 01:30:00 EST-0500 | |
364 | |
365 If you pass None as the is_dst flag to localize(), pytz will refuse to | |
366 guess and raise exceptions if you try to build ambiguous or non-existent | |
367 times. | |
368 | |
369 For example, 1:30am on 27th Oct 2002 happened twice in the US/Eastern | |
370 timezone when the clocks where put back at the end of Daylight Saving | |
371 Time: | |
372 | |
373 >>> dt = datetime(2002, 10, 27, 1, 30, 00) | |
374 >>> try: | |
375 ... eastern.localize(dt, is_dst=None) | |
376 ... except pytz.exceptions.AmbiguousTimeError: | |
377 ... print('pytz.exceptions.AmbiguousTimeError: %s' % dt) | |
378 pytz.exceptions.AmbiguousTimeError: 2002-10-27 01:30:00 | |
379 | |
380 Similarly, 2:30am on 7th April 2002 never happened at all in the | |
381 US/Eastern timezone, as the clocks where put forward at 2:00am skipping | |
382 the entire hour: | |
383 | |
384 >>> dt = datetime(2002, 4, 7, 2, 30, 00) | |
385 >>> try: | |
386 ... eastern.localize(dt, is_dst=None) | |
387 ... except pytz.exceptions.NonExistentTimeError: | |
388 ... print('pytz.exceptions.NonExistentTimeError: %s' % dt) | |
389 pytz.exceptions.NonExistentTimeError: 2002-04-07 02:30:00 | |
390 | |
391 Both of these exceptions share a common base class to make error handling | |
392 easier: | |
393 | |
394 >>> isinstance(pytz.AmbiguousTimeError(), pytz.InvalidTimeError) | |
395 True | |
396 >>> isinstance(pytz.NonExistentTimeError(), pytz.InvalidTimeError) | |
397 True | |
398 | |
399 | |
400 A special case is where countries change their timezone definitions | |
401 with no daylight savings time switch. For example, in 1915 Warsaw | |
402 switched from Warsaw time to Central European time with no daylight savings | |
403 transition. So at the stroke of midnight on August 5th 1915 the clocks | |
404 were wound back 24 minutes creating an ambiguous time period that cannot | |
405 be specified without referring to the timezone abbreviation or the | |
406 actual UTC offset. In this case midnight happened twice, neither time | |
407 during a daylight saving time period. pytz handles this transition by | |
408 treating the ambiguous period before the switch as daylight savings | |
409 time, and the ambiguous period after as standard time. | |
410 | |
411 | |
412 >>> warsaw = pytz.timezone('Europe/Warsaw') | |
413 >>> amb_dt1 = warsaw.localize(datetime(1915, 8, 4, 23, 59, 59), is_dst=True) | |
414 >>> amb_dt1.strftime(fmt) | |
415 '1915-08-04 23:59:59 WMT+0124' | |
416 >>> amb_dt2 = warsaw.localize(datetime(1915, 8, 4, 23, 59, 59), is_dst=False) | |
417 >>> amb_dt2.strftime(fmt) | |
418 '1915-08-04 23:59:59 CET+0100' | |
419 >>> switch_dt = warsaw.localize(datetime(1915, 8, 5, 00, 00, 00), is_dst=False) | |
420 >>> switch_dt.strftime(fmt) | |
421 '1915-08-05 00:00:00 CET+0100' | |
422 >>> str(switch_dt - amb_dt1) | |
423 '0:24:01' | |
424 >>> str(switch_dt - amb_dt2) | |
425 '0:00:01' | |
426 | |
427 The best way of creating a time during an ambiguous time period is | |
428 by converting from another timezone such as UTC: | |
429 | |
430 >>> utc_dt = datetime(1915, 8, 4, 22, 36, tzinfo=pytz.utc) | |
431 >>> utc_dt.astimezone(warsaw).strftime(fmt) | |
432 '1915-08-04 23:36:00 CET+0100' | |
433 | |
434 The standard Python way of handling all these ambiguities is not to | |
435 handle them, such as demonstrated in this example using the US/Eastern | |
436 timezone definition from the Python documentation (Note that this | |
437 implementation only works for dates between 1987 and 2006 - it is | |
438 included for tests only!): | |
439 | |
440 >>> from pytz.reference import Eastern # pytz.reference only for tests | |
441 >>> dt = datetime(2002, 10, 27, 0, 30, tzinfo=Eastern) | |
442 >>> str(dt) | |
443 '2002-10-27 00:30:00-04:00' | |
444 >>> str(dt + timedelta(hours=1)) | |
445 '2002-10-27 01:30:00-05:00' | |
446 >>> str(dt + timedelta(hours=2)) | |
447 '2002-10-27 02:30:00-05:00' | |
448 >>> str(dt + timedelta(hours=3)) | |
449 '2002-10-27 03:30:00-05:00' | |
450 | |
451 Notice the first two results? At first glance you might think they are | |
452 correct, but taking the UTC offset into account you find that they are | |
453 actually two hours appart instead of the 1 hour we asked for. | |
454 | |
455 >>> from pytz.reference import UTC # pytz.reference only for tests | |
456 >>> str(dt.astimezone(UTC)) | |
457 '2002-10-27 04:30:00+00:00' | |
458 >>> str((dt + timedelta(hours=1)).astimezone(UTC)) | |
459 '2002-10-27 06:30:00+00:00' | |
460 | |
461 | |
462 Country Information | |
463 ~~~~~~~~~~~~~~~~~~~ | |
464 | |
465 A mechanism is provided to access the timezones commonly in use | |
466 for a particular country, looked up using the ISO 3166 country code. | |
467 It returns a list of strings that can be used to retrieve the relevant | |
468 tzinfo instance using ``pytz.timezone()``: | |
469 | |
470 >>> print(' '.join(pytz.country_timezones['nz'])) | |
471 Pacific/Auckland Pacific/Chatham | |
472 | |
473 The Olson database comes with a ISO 3166 country code to English country | |
474 name mapping that pytz exposes as a dictionary: | |
475 | |
476 >>> print(pytz.country_names['nz']) | |
477 New Zealand | |
478 | |
479 | |
480 What is UTC | |
481 ~~~~~~~~~~~ | |
482 | |
483 'UTC' is `Coordinated Universal Time`_. It is a successor to, but distinct | |
484 from, Greenwich Mean Time (GMT) and the various definitions of Universal | |
485 Time. UTC is now the worldwide standard for regulating clocks and time | |
486 measurement. | |
487 | |
488 All other timezones are defined relative to UTC, and include offsets like | |
489 UTC+0800 - hours to add or subtract from UTC to derive the local time. No | |
490 daylight saving time occurs in UTC, making it a useful timezone to perform | |
491 date arithmetic without worrying about the confusion and ambiguities caused | |
492 by daylight saving time transitions, your country changing its timezone, or | |
493 mobile computers that roam through multiple timezones. | |
494 | |
495 .. _Coordinated Universal Time: https://en.wikipedia.org/wiki/Coordinated_Universal_Time | |
496 | |
497 | |
498 Helpers | |
499 ~~~~~~~ | |
500 | |
501 There are two lists of timezones provided. | |
502 | |
503 ``all_timezones`` is the exhaustive list of the timezone names that can | |
504 be used. | |
505 | |
506 >>> from pytz import all_timezones | |
507 >>> len(all_timezones) >= 500 | |
508 True | |
509 >>> 'Etc/Greenwich' in all_timezones | |
510 True | |
511 | |
512 ``common_timezones`` is a list of useful, current timezones. It doesn't | |
513 contain deprecated zones or historical zones, except for a few I've | |
514 deemed in common usage, such as US/Eastern (open a bug report if you | |
515 think other timezones are deserving of being included here). It is also | |
516 a sequence of strings. | |
517 | |
518 >>> from pytz import common_timezones | |
519 >>> len(common_timezones) < len(all_timezones) | |
520 True | |
521 >>> 'Etc/Greenwich' in common_timezones | |
522 False | |
523 >>> 'Australia/Melbourne' in common_timezones | |
524 True | |
525 >>> 'US/Eastern' in common_timezones | |
526 True | |
527 >>> 'Canada/Eastern' in common_timezones | |
528 True | |
529 >>> 'Australia/Yancowinna' in all_timezones | |
530 True | |
531 >>> 'Australia/Yancowinna' in common_timezones | |
532 False | |
533 | |
534 Both ``common_timezones`` and ``all_timezones`` are alphabetically | |
535 sorted: | |
536 | |
537 >>> common_timezones_dupe = common_timezones[:] | |
538 >>> common_timezones_dupe.sort() | |
539 >>> common_timezones == common_timezones_dupe | |
540 True | |
541 >>> all_timezones_dupe = all_timezones[:] | |
542 >>> all_timezones_dupe.sort() | |
543 >>> all_timezones == all_timezones_dupe | |
544 True | |
545 | |
546 ``all_timezones`` and ``common_timezones`` are also available as sets. | |
547 | |
548 >>> from pytz import all_timezones_set, common_timezones_set | |
549 >>> 'US/Eastern' in all_timezones_set | |
550 True | |
551 >>> 'US/Eastern' in common_timezones_set | |
552 True | |
553 >>> 'Australia/Victoria' in common_timezones_set | |
554 False | |
555 | |
556 You can also retrieve lists of timezones used by particular countries | |
557 using the ``country_timezones()`` function. It requires an ISO-3166 | |
558 two letter country code. | |
559 | |
560 >>> from pytz import country_timezones | |
561 >>> print(' '.join(country_timezones('ch'))) | |
562 Europe/Zurich | |
563 >>> print(' '.join(country_timezones('CH'))) | |
564 Europe/Zurich | |
565 | |
566 | |
567 Internationalization - i18n/l10n | |
568 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
569 | |
570 Pytz is an interface to the IANA database, which uses ASCII names. The `Unicode Consortium's Unicode Locales (CLDR) <http://cldr.unicode.org>`_ | |
571 project provides translations. Python packages such as | |
572 `Babel <https://babel.pocoo.org/en/latest/api/dates.html#timezone-functionality>`_ | |
573 and Thomas Khyn's `l18n <https://pypi.org/project/l18n/>`_ package can be used | |
574 to access these translations from Python. | |
575 | |
576 | |
577 License | |
578 ~~~~~~~ | |
579 | |
580 MIT license. | |
581 | |
582 This code is also available as part of Zope 3 under the Zope Public | |
583 License, Version 2.1 (ZPL). | |
584 | |
585 I'm happy to relicense this code if necessary for inclusion in other | |
586 open source projects. | |
587 | |
588 | |
589 Latest Versions | |
590 ~~~~~~~~~~~~~~~ | |
591 | |
592 This package will be updated after releases of the Olson timezone | |
593 database. The latest version can be downloaded from the `Python Package | |
594 Index <https://pypi.org/project/pytz/>`_. The code that is used | |
595 to generate this distribution is hosted on Github and available | |
596 using git:: | |
597 | |
598 git clone https://github.com/stub42/pytz.git | |
599 | |
600 Announcements of new releases are made on | |
601 `Launchpad <https://launchpad.net/pytz>`_, and the | |
602 `Atom feed <http://feeds.launchpad.net/pytz/announcements.atom>`_ | |
603 hosted there. | |
604 | |
605 | |
606 Bugs, Feature Requests & Patches | |
607 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
608 | |
609 Bugs should be reported on `Github <https://github.com/stub42/pytz/issues>`_. | |
610 Feature requests are unlikely to be considered, and efforts instead directed | |
611 to timezone support now built into Python or packages that work with it. | |
612 | |
613 | |
614 Security Issues | |
615 ~~~~~~~~~~~~~~~ | |
616 | |
617 Reports about security issues can be made via `Tidelift <https://tidelift.com/security>`_. | |
618 | |
619 | |
620 Issues & Limitations | |
621 ~~~~~~~~~~~~~~~~~~~~ | |
622 | |
623 - This project is in maintenance mode. Projects using Python 3.9 or later | |
624 are best served by using the timezone functionaly now included in core | |
625 Python and packages that work with it such as `tzdata <https://pypi.org/project/tzdata/>`_. | |
626 | |
627 - Offsets from UTC are rounded to the nearest whole minute, so timezones | |
628 such as Europe/Amsterdam pre 1937 will be up to 30 seconds out. This | |
629 was a limitation of the Python datetime library. | |
630 | |
631 - If you think a timezone definition is incorrect, I probably can't fix | |
632 it. pytz is a direct translation of the Olson timezone database, and | |
633 changes to the timezone definitions need to be made to this source. | |
634 If you find errors they should be reported to the time zone mailing | |
635 list, linked from http://www.iana.org/time-zones. | |
636 | |
637 | |
638 Further Reading | |
639 ~~~~~~~~~~~~~~~ | |
640 | |
641 More info than you want to know about timezones: | |
642 https://data.iana.org/time-zones/tz-link.html | |
643 | |
644 | |
645 Contact | |
646 ~~~~~~~ | |
647 | |
648 Stuart Bishop <stuart@stuartbishop.net> |