METADATA 22 KB

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