METADATA 22 KB

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